DBMS 1 Unit1
DBMS 1 Unit1
MANAGEMENT SYSTEMS
UNIT -1 INTRODUCTION
INTRODUCTION
• Data
• Data is information (or) set of values that has been
gathered and translated for some purpose, usually
analysis.
• It can be any character, including text, numbers,
pictures, sound and video suitable for use with a
computer.
• Database
• A database is a collection of information that is
organized so that it can be easily accessed, managed
and updated.
File Processing System
• A File Processing System is a collection of data, files
and records.
• In initial days, these records were stored in the form
of files. (Papers and notepad etc..)
• Each fields of information separated by space, tab,
comma, semicolon or any other symbol.
• Before DBMS were introduced, organizations usually
stored information in such systems.
Disadvantages of FPS
• Data redundancy
• It is possible that the same information may be
duplicated in different files. This leads to data
redundancy. It results in memory wastage.
• Data inconsistency
• data may not be in consistent state.
• Difficulty in accessing data
• Accessing data is not convenient and efficient in
conventional file processing system.
Disadvantages of FPS
• Data Isolation
• Data are separated in various files.
• Different files may have different formats.
• These files may be stored in different folders or
different computers.
• So, due to this data isolation, it is difficult to share
data among different applications.
• Integrity problems
• It refers to the accuracy and consistency of data
stored in a database.
• Data values stored in the database must satisfy
certain types of constraints.
Disadvantages of FPS
• Atomicity problems
• File system does not guarantee the atomicity.
• If there is any failure to insert, update or delete in
the file system, there is no mechanism to switch
back to the previous state.
• Concurrent-access anomalies
• Multiple users are allowed to access data
simultaneously for better performance and faster
response.
• In the file system, concurrent access leads to
incorrect data.
Disadvantages of FPS
• Security problems
• Not every user of the database system should be
able to access all the data.
Comparison
File Processing System DBMS
• File-based system • Database system
caused data redundancy. control data
The data may be redundancy. The data
duplicated in different appeared only once in
files the system.
• File –based system • In database system data
caused data always consistent.
inconsistency. The data Because data appeared
in different files may be only once.
different that cause data
inconsistency.
Comparison
File Processing System DBMS
• The data cannot be • In database data is
shared because data is easily shared because
distributed in different data is stored at one
files. place.
• File based system does • Database system
not provide consistency provides a different
constrains consistency constrains
to maintain data
integrity in the system
Comparison
File Processing System DBMS
• The cost of file • The cost of database
processing system is system is much more
less then database than a file processing
system. system.
• File based system does • Database system
not provide provides concurrency
concurrency facility. facility.
• File based system does • Database system
not provide data provides data atomicity
atomicity functionality. functionality
PURPOSE OF
DATABASE SYSTEMS
• In the early days, database applications were built on top of
file systems
• Drawbacks of using file systems to store data:
• Data redundancy and inconsistency
• Multiple file formats, duplication of information in
different files
• Difficulty in accessing data
• Need to write a new program to carry out each new task
• Data isolation — multiple files and formats
• Integrity problems
• Integrity constraints (e.g. account balance > 0) become
part of program code
• Hard to add new constraints or change existing ones
PURPOSE OF
DATABASE SYSTEMS
• Drawbacks of using file systems (cont.)
• Atomicity of updates
• Failures may leave database in an inconsistent state with
partial updates carried out
• E.g. transfer of funds from one account to another should
either complete or not happen at all
• Concurrent access by multiple users
• Concurrent accessed needed for performance
• Uncontrolled concurrent accesses can lead to
inconsistencies
• E.g. two people reading a balance and updating it at the
same time
• Security problems
• Database systems offer solutions to all the above problems
Database Applications
• Banking: transactions
• Airlines: reservations, schedules
• Universities: registration, grades
• Sales: customers, products, purchases
• Online retailers: order tracking, customized
recommendations
• Manufacturing: production, inventory, orders, supply
chain
• Human resources: employee records, salaries, tax
deductions
Elements of Database
• Tables
• Constraints - maintain
the data integrity during an
update/delete/insert into a
table.
DROP
DROP TABLE TABLE NAME;
TRUNCATE:
TRUNCATE TABLE TABLE NAME;
RENAME:
RENAME OLD TABLE NAME TO NEW TABLE
NAME;
DQL (Data Query Language) :
• DML statements are used for performing
queries on the data within schema objects.
The purpose of DQL Command is to get some
schema relation based on the query passed
to it.
• Example of DQL:
• SELECT – is used to retrieve data from the a
database.
SELECT * FROM TABLE NAME;
DML(Data Manipulation Language) : The SQL
commands that deals with the manipulation of data
present in the database belong to DML or Data
Manipulation Language and this includes most of the
SQL statements.Examples of DML:
• INSERT – is used to insert data into a table.
• UPDATE – is used to update existing data within a table.
• DELETE – is used to delete records from a database table.
• Merge: It performs UPSERT operation, i.e., insert or update
operations.
• Call: It is used to call a structured query language .
• Explain Plan: It has the parameter of explaining data.
• Lock Table: It controls concurrency.
INSERT:
INSERT INTO TABLE_NAME
(col1, col2, col3,.... col N)
VALUES (value1, value2, value3, .... valueN);
INSERT:
INSERT INTO TABLE_NAME
VALUES (value1, value2, value3, .... valueN);
• For example:
UPDATE:
UPDATE table_name SET [column_name1= valu
e1,...column_nameN = valueN] [WHERE CONDI
TION]
DELETE:
DELETE FROM table_name [WHERE condition];
DCL(Data Control Language) : DCL includes
commands such as GRANT and REVOKE which
mainly deals with the rights, permissions and
other controls of the database
system.Examples of DCL commands:
• GRANT-gives user’s access privileges to
database.
• REVOKE-withdraw user’s access privileges
given by using the GRANT command.
GRANT:
GRANT SELECT, UPDATE ON MY_TABLE TO SOM
E_USER, ANOTHER_USER;
REVOKE:
REVOKE SELECT, UPDATE ON MY_TABLE FROM
USER1, USER2;
TCL(transaction Control Language) : TCL
commands deals with the
transaction within the database.Examples of
TCL commands:
• COMMIT– commits (SAVE) a Transaction.
• ROLLBACK– rollbacks a transaction in case of
any error occurs.
• SAVEPOINT–sets a savepoint within a
transaction. ie) It is used to roll the transaction back to a
certain point without rolling back the entire transaction.
• SET TRANSACTION–specify characteristics
for the transaction.
COMMIT:
COMMIT;
ROLLBACK:
ROLLBACK;
SAVEPOINT:
SAVEPOINT SAVEPOINT_NAME;
Data
Independence
• Data independence can be explained using
the three-schema architecture.
• Data independence refers characteristic of
being able to modify the schema at one level
of the database system without altering the
schema at the next higher level.
There are two types of data independence:
1.Logical Data Independence
2. Physical Data Independence
Logical Data Independence
• Logical data independence refers characteristic
of being able to change the conceptual schema
without having to change the external schema.
• Logical data independence is used to separate
the external level from the conceptual view.
• If we do any changes in the conceptual view of
the data, then the user view of the data would
not be affected.
• Logical data independence occurs at the user
interface level.
Physical Data Independence
• Physical data independence can be defined as
the capacity to change the internal schema
without having to change the conceptual
schema.
• If we do any changes in the storage size of the
database system server, then the Conceptual
structure of the database will not be affected.
• Physical data independence is used to
separate conceptual levels from the internal
levels.
• Physical data independence occurs at the
logical interface level.