Dbms Notes
Dbms Notes
Data: Data is nothing but facts and statistics stored or free flowing over a
network, generally it's raw and unprocessed.
Information: Data becomes information when it is processed, turning it into
something meaningful.
Database: It is collection of related data stored electronically in a systematic
manner.
Database Management system: It is the system to manage database by the user.
Examples- SQL, MySQL, Oracle, IBMDB2 etc.
Creation of table
Rows, columns, tables
ER Model
Relationship:
1. One to One: A female can marry to one male vice versa.
2. One to many: A scientist can invent many inventions but an invention is done
by the only specific scientist.
3. Many to One: Student enrols for only one course but a course has many
students.
4. Many to Many: Employee and project relationship.
DBMS Languages***
1. DDL (Data Definition Language): Create, rename, Drop, Alter, Truncate, Comment.
It is used to define the database schema.
Create: create database or Table (Column and types of data in column, size
of data) e.g. Roll_no int(3), Name varchar(20).
Drop**: delete a whole database or just a table permanently.
e.g. Drop TABLE Class_VI, Drop DATABASE School
Truncate: remove all the records from a table including all spaces.
ALTER**: ( Add, modify) It is used to add, delete or modify columns in
the existing table. E.g. To add 2 columns Age and Course to table Student.
ALTER TABLE Student ADD ( Age number(3), course varchar(40))
Comment: can be written in single line, multiple lines.
Note: Truncate preserves the structure of table for further use unlike drop table
where the table is deleted with its full structure.
2. DML (Data Manipulation Language): Select, Insert, Update, Delete
DML request data from DBMS by using application programs hence can be
embedded in programs.
Select: fetch data from database and one or more than one tables.
e.g. select column_name_1, column_name_2, … from Table_name.
Insert: insert new row in a table.
Update: Update Employee-Set Emp_salary= 1000 Where EMP_Age> 25;
Delete: delete existing records/ rows from a table. E.g. Delete from Student
where Name = “Ram” .
3. DCL (Data Control Language): deals with rights, permissions and other
controls of database. GRANT, REVOKE.
4. TCL (Transaction Control Language): Commit, Rollback, Set transaction.
Procedure for Database Access
Data Manager: It determines which physical record is asked by user and sends
request for specific physical record to File manager.
File Manager: It decides which physical block of secondary storage devices
contains the required record and sends the request for the appropriate block to the
disk manager.
Database Users:
1. Naïve Users: use easy to use menu; e.g. ATM
2. Sophisticated Users: They interact with the system by writing SQL queries
directly through the query processor without writing application programs.
3. Application Programmers: computer professionals who interact with system
through DML. They write application programs.
4. Specialized users: They are also sophisticated users who write specialized
database applications that do not fit into the traditional data processing
framework. Example: Expert System, Knowledge Based System, etc.
Database Administrator(DNA)**
administration and maintenance of database is taken care by DBA.
Creating the schema
Specifying integrity constraints
Storage structure and access method definition
Granting permission to other users.
Monitoring performance
Routine Maintenance
ACID Properties of DBMS: to maintain integrity of database.
A- Atomicity: A transaction is a single unit of operation. You either execute it
entirely or do not execute it at all. There cannot be partial execution.
C- Consistency: Once the transaction is executed, it should move from one
consistent state to another.
I- Isolation:
D:Durability: After successful completion of a transaction, the changes in the
database should persist. Even in the case of system failures.
Keys in DBMS***: A key is an attribute or set of attributes that uniquely
identifies any record (tuple) from the table. In the below table to identify specific
Neha we can use unique Emp_Id, Aadhar_no etc.
1. Super Key: A combination of all the possible attributes that can uniquely
identify the rows. Superset.
2. Candidate Key: A candidate key is a minimal super key or Super key with no
redundant attributes. It is defined as distinct set of attributes from which primary
key can be selected. Not allowed to be a null value.
3. Primary Key: It is one of the candidate key chosen by the database designer to
uniquely identify the tuple in the relation.
Value never be null
Value always be unique
No updation possible for value
A relation is allowed to have only one primary key.
4. Alternate Key: Out of all candidate keys, only one gets selected as primary key
and remaining keys are known as alternate keys.
5. Foreign Key: A foreign key is used to link two tables together. An attribute (or
set of attributes) in one table that refers to the primary key in another table.
The purpose of foreign key is to ensure referential integrity of data.
It can take only those values which are present in the primary key of the
referenced relation.
It can take null value or have a duplicate value.
Referenced table is also called Primary Table or Parent Table.
Referencing Table may be called as Foreign or Child table.
6. Composite key: A key that has more than one attributes is known as Composite/
compound key.
Data Dictionary:
It is used to store all the details of database like table names, name of all the fields,
width and types of all the fields etc. in a tabular format. It contains name and
description of each data element.
It is maintained and exclusively used by data administrator.
Integrity Constraint**:
Integrity constraints ensure that the data insertion, updating, and other processes
have to be performed in such a way that data integrity is not affected hence guard
against accidental damage to database.
1. Domain Constraint:
4. Key Constraints:
An entity set can have multiple keys, but out of which one key will be the primary
key. A primary key can contain only a unique and null value in the relational
table.