You are on page 1of 16

What is Data?

Data is a collection of a distinct small unit of information. It can be used in a variety of


forms like text, numbers, media, bytes, etc. it can be stored in pieces of paper or
electronic memory, etc.

Word 'Data' is originated from the word 'datum' that means 'single piece of
information.' It is plural of the word datum.

In computing, Data is information that can be translated into a form for efficient
movement and processing. Data is interchangeable.

What is Database?
A database is an organized collection of data, so that it can be easily accessed and
managed.

You can organize data into tables, rows, columns, and index it to make it easier to find
relevant information.

Database handlers create a database in such a way that only one set of software
program provides access of data to all the users.

The main purpose of the database is to operate a large amount of information by


storing, retrieving, and managing data.

There are many dynamic websites on the World Wide Web nowadays which are
handled through databases. For example, a model that checks the availability of rooms
in a hotel. It is an example of a dynamic website that uses a database.

There are many databases available like MySQL, Sybase, Oracle, MongoDB, Informix,
PostgreSQL, SQL Server, etc.

File System Approach


File based systems were an early attempt to computerize the manual system. It is also
called a traditional based approach in which a decentralized approach was taken where
each department stored and controlled its own data with the help of a data processing
specialist. The main role of a data processing specialist was to create the necessary
computer file structures, and also manage the data within structures and design some
application programs that create reports based on file data.

In the above figure:

Consider an example of a student's file system. The student file will contain information
regarding the student (i.e. roll no, student name, course etc.). Similarly, we have a
subject file that contains information about the subject and the result file which contains
the information regarding the result.

Some fields are duplicated in more than one file, which leads to data redundancy. So to
overcome this problem, we need to create a centralized system, i.e. DBMS approach.

DBMS:
A database approach is a well-organized collection of data that are related in a
meaningful way which can be accessed by different users but stored only once in a
system. The various operations performed by the DBMS system are: Insertion, deletion,
selection, sorting etc.
In the above figure,

In the above figure, duplication of data is reduced due to centralization of data.

There are the following differences between DBMS and File systems:

Basis DBMS Approach File System Approach

Meaning DBMS is a collection of data. In The file system is a collection of


DBMS, the user is not required to data. In this system, the user
write the procedures. has to write the procedures for
managing the database.

Sharing of data Due to the centralized approach, Data is distributed in many files,
data sharing is easy. and it may be of different
formats, so it isn't easy to share
data.

Data DBMS gives an abstract view of The file system provides the
Abstraction data that hides the details. detail of the data
representation and storage of
data.

Security and DBMS provides a good protection It isn't easy to protect a file
Protection mechanism. under the file system.

Recovery DBMS provides a crash recovery The file system doesn't have a
Mechanism mechanism, i.e., DBMS protects the crash mechanism, i.e., if the
user from system failure. system crashes while entering
some data, then the content of
the file will be lost.

Manipulation DBMS contains a wide variety of The file system can't efficiently
Techniques sophisticated techniques to store store and retrieve the data.
and retrieve the data.

Concurrency DBMS takes care of Concurrent In the File system, concurrent


Problems access of data using some form of access has many problems like
locking. redirecting the file while
deleting some information or
updating some information.

Where to use Database approach used in large File system approach used in
systems which interrelate many large systems which interrelate
files. many files.

Cost The database system is expensive The file system approach is


to design. cheaper to design.

Data Due to the centralization of the In this, the files and application
Redundancy and database, the problems of data programs are created by
Inconsistency redundancy and inconsistency are different programmers so that
controlled. there exists a lot of duplication
of data which may lead to
inconsistency.

Structure The database structure is complex The file system approach has a
to design. simple structure.

Data In this system, Data Independence In the File system approach,


Independence exists, and it can be of two types. there exists no Data
o Logical Data Independence Independence.
o Physical Data Independence

Integrity Integrity Constraints are easy to Integrity Constraints are difficult


Constraints apply. to implement in file system.

Data Models In the database approach, 3 types In the file system approach,
of data models exist: there is no concept of data
o Hierarchal data models models exists.

o Network data models


o Relational data models

Flexibility Changes are often a necessity to The flexibility of the system is


the content of the data stored in less as compared to the DBMS
any system, and these changes are approach.
more easily with a database
approach.

Examples Oracle, SQL Server, Sybase etc. Cobol, C++ etc.

Applications of DBMS
In so many fields, we will use a database management system.
Let’s see some of the applications where database management system uses −
 Railway Reservation System − The railway reservation system database plays
a very important role by keeping record of ticket booking, train’s departure time
and arrival status and also gives information regarding train late to people
through the database.
 Library Management System − Now-a-days it’s become easy in the Library to
track each book and maintain it because of the database. This happens because
there are thousands of books in the library. It is very difficult to keep a record of
all books in a copy or register. Now DBMS used to maintain all the information
related to book issue dates, name of the book, author and availability of the book.

 Banking − Banking is one of the main applications of databases. We all know


there will be a thousand transactions through banks daily and we are doing this
without going to the bank. This is all possible just because of DBMS that
manages all the bank transactions.
 Universities and colleges − Now-a-days examinations are done online. So, the
universities and colleges are maintaining DBMS to store Student’s registrations
details, results, courses and grade all the information in the database. For
example, telecommunications. Without DBMS there is no telecommunication
company. DBMS is most useful to these companies to store the call details and
monthly postpaid bills.
 Credit card transactions − The purchase of items and transactions of credit
cards are made possible only by DBMS. A credit card holder has to know the
importance of their information that all are secured through DBMS.
 Social Media Sites − By filling the required details we are able to access social
media platforms. Many users sign up daily on social websites such as Facebook,
Pinterest and Instagram. All the information related to the users are stored and
maintained with the help of DBMS.
 Finance − Now-a-days there are lots of things to do with finance like storing
sales, holding information and finance statement management etc. these all can
be done with database systems.
 Military − In military areas the DBMS is playing a vital role. Military keeps
records of soldiers and it has so many files that should be kept secure and safe.
DBMS provides a high security to military information.
 Online Shopping − Now-a-days we all do Online shopping without wasting the
time by going shopping with the help of DBMS. The products are added and sold
only with the help of DBMS like Purchase information, invoice bills and payment.
 Human Resource Management − The management keeps records of each
employee’s salary, tax and work through DBMS.
 Manufacturing − Manufacturing companies make products and sell them on a
daily basis. To keep records of all those details DBMS is used.
 Airline Reservation system − Just like the railway reservation system, airlines
also need DBMS to keep records of flights arrival, departure and delay status.

Database Users
Database users are the ones who really use and take the benefits of the
database. There will be different types of users depending on their needs and
way of accessing the database.

1. Application Programmers – They are the developers who interact with


the database by means of DML queries. These DML queries are written
in the application programs like C, C++, JAVA, Pascal, etc. These
queries are converted into object code to communicate with the
database. For example, writing a C program to generate the report of
employees who are working in a particular department will involve a
query to fetch the data from the database. It will include an embedded
SQL query in the C Program.
2. Sophisticated Users – They are database developers, who write SQL
queries to select/insert/delete/update data. They do not use any
application or programs to request the database. They directly interact
with the database by means of a query language like SQL. These users
will be scientists, engineers, analysts who thoroughly study SQL and
DBMS to apply the concepts in their requirements. In short, we can say
this category includes designers and developers of DBMS and SQL.
3. Specialized Users – These are also sophisticated users, but they write
special database application programs. They are the developers who
develop the complex programs to the requirement.
4. Stand-alone Users – These users will have a stand-alone database for
their personal use. These kinds of the database will have readymade
database packages which will have menus and graphical interfaces.
5. Native Users – these are the users who use the existing application to
interact with the database. For example, online library system, ticket
booking systems, ATMs etc which has existing application and users
use them to interact with the database to fulfill their requests.

SQL
o SQL stands for Structured Query Language. It is used for storing and managing data in
relational database management system (RDMS).
o It is a standard language for Relational Database System. It enables a user to create,
read, update and delete relational databases and tables.
o All the RDBMS like MySQL, Informix, Oracle, MS Access and SQL Server use SQL as their
standard database language.
o SQL allows users to query the database in a number of ways, using English-like
statements.

Rules:
SQL follows the following rules:

o Structure query language is not case sensitive. Generally, keywords of SQL are written in
uppercase.
o Statements of SQL are dependent on text lines. We can use a single SQL statement on
one or multiple text line.
o Using the SQL statements, you can perform most of the actions in a database.
o SQL depends on tuple relational calculus and relational algebra.

SQL Datatype
o SQL Datatype is used to define the values that a column can contain.
o Every column is required to have a name and data type in the database table.

Datatype of SQL:

1. Binary Datatypes
There are Three types of binary Datatypes which are given below:

Data Type Description

binary It has a maximum length of 8000 bytes. It contains fixed-length binary data.
varbinary It has a maximum length of 8000 bytes. It contains variable-length binary data.

image It has a maximum length of 2,147,483,647 bytes. It contains variable-length binary data.

2. Approximate Numeric Datatype :


The subtypes are given below:

Data type From To Description

float -1.79E + 308 1.79E + 308 It is used to specify a floating-point value e.g. 6.2, 2.9 etc.

real -3.40e + 38 3.40E + 38 It specifies a single precision floating point number

3. Exact Numeric Datatype


The subtypes are given below:

Data type Description

int It is used to specify an integer value.

smallint It is used to specify small integer value.

bit It has the number of bits to store.

decimal It specifies a numeric value that can have a decimal number.

numeric It is used to specify a numeric value.

4. Character String Datatype


The subtypes are given below:
Data Description
type

char It has a maximum length of 8000 characters. It contains Fixed-length non-unicode characters.

varchar It has a maximum length of 8000 characters. It contains variable-length non-unicode characters.

text It has a maximum length of 2,147,483,647 characters. It contains variable-length non-unicod


characters.

5. Date and time Datatypes


The subtypes are given below:

Datatype Description

date It is used to store the year, month, and days value.

time It is used to store the hour, minute, and second values.

timestamp It stores the year, month, day, hour, minute, and the second value.

SQL Commands
o SQL commands are instructions. It is used to communicate with the database. It is also
used to perform specific tasks, functions, and queries of data.
o SQL can perform various tasks like create a table, add data to tables, drop the table,
modify the table, set permission for users.

Types of SQL Commands


There are five types of SQL commands: DDL, DML, DCL, TCL, and DQL.

1. Data Definition Language (DDL)


o DDL changes the structure of the table like creating a table, deleting a table, altering a
table, etc.
o All the command of DDL are auto-committed that means it permanently save all the
changes in the database.

Here are some commands that come under DDL:

o CREATE
o ALTER
o DROP
o TRUNCATE

a. CREATE It is used to create a new table in the database.


Syntax:

1. CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,....]);

Example:

1. CREATE TABLE EMPLOYEE(Name VARCHAR2(20), Email VARCHAR2(100), DOB DATE);

b. DROP: It is used to delete both the structure and record stored in the table.

Syntax

1. DROP TABLE table_name;

Example

1. DROP TABLE EMPLOYEE;

c. ALTER: It is used to alter the structure of the database. This change could be either to
modify the characteristics of an existing attribute or probably to add a new attribute.

Syntax:

To add a new column in the table

1. ALTER TABLE table_name ADD column_name COLUMN-definition;

To modify existing column in the table:

1. ALTER TABLE table_name MODIFY(column_definitions....);

EXAMPLE

1. ALTER TABLE STU_DETAILS ADD(ADDRESS VARCHAR2(20));


2. ALTER TABLE STU_DETAILS MODIFY (NAME VARCHAR2(20));

d. TRUNCATE: It is used to delete all the rows from the table and free the space
containing the table.

Syntax:
1. TRUNCATE TABLE table_name;

Example:

1. TRUNCATE TABLE EMPLOYEE;


2. Data Manipulation Language
o DML commands are used to modify the database. It is responsible for all form of
changes in the database.
o The command of DML is not auto-committed that means it can't permanently save all
the changes in the database. They can be rollback.

Here are some commands that come under DML:

o INSERT
o UPDATE
o DELETE

a. INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of
a table.

Syntax:

1. INSERT INTO TABLE_NAME


2. (col1, col2, col3,.... col N)
3. VALUES (value1, value2, value3, .... valueN);

Or

1. INSERT INTO TABLE_NAME


2. VALUES (value1, value2, value3, .... valueN);

For example:

1. INSERT INTO javatpoint (Author, Subject) VALUES ("Sonoo", "DBMS");

b. UPDATE: This command is used to update or modify the value of a column in the
table.
Syntax:

1. UPDATE table_name SET [column_name1= value1,...column_nameN = valueN] [WHERE CONDITI


ON]

For example:

1. UPDATE students
2. SET User_Name = 'Sonoo'
3. WHERE Student_Id = '3'

c. DELETE: It is used to remove one or more row from a table.

Syntax:

1. DELETE FROM table_name [WHERE condition];

For example:

1. DELETE FROM javatpoint


2. WHERE Author="Sonoo";
3. Data Control Language
DCL commands are used to grant and take back authority from any database user.

Here are some commands that come under DCL:

o Grant
o Revoke

a. Grant: It is used to give user access privileges to a database.

Example

1. GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTHER_USER;

b. Revoke: It is used to take back permissions from the user.

Example
1. REVOKE SELECT, UPDATE ON MY_TABLE FROM USER1, USER2;
4. Transaction Control Language
TCL commands can only use with DML commands like INSERT, DELETE and UPDATE
only.

These operations are automatically committed in the database that's why they cannot
be used while creating tables or dropping them.

Here are some commands that come under TCL:

o COMMIT
o ROLLBACK
o SAVEPOINT

a. Commit: Commit command is used to save all the transactions to the database.

Syntax:

1. COMMIT;

Example:

1. DELETE FROM CUSTOMERS


2. WHERE AGE = 25;
3. COMMIT;

b. Rollback: Rollback command is used to undo transactions that have not already been
saved to the database.

Syntax:

1. ROLLBACK;

Example:

1. DELETE FROM CUSTOMERS


2. WHERE AGE = 25;
3. ROLLBACK;
c. SAVEPOINT: It is used to roll the transaction back to a certain point without rolling
back the entire transaction.

Syntax:

1. SAVEPOINT SAVEPOINT_NAME;
5. Data Query Language
DQL is used to fetch the data from the database.

It uses only one command:

o SELECT

a. SELECT: This is the same as the projection operation of relational algebra. It is used to
select the attribute based on the condition described by WHERE clause.

Syntax:

1. SELECT expressions
2. FROM TABLES
3. WHERE conditions;

For example:

1. SELECT emp_name
2. FROM employee
3. WHERE age > 20;

You might also like