PC03 DBMS Notes V-2 by Rajeev
PC03 DBMS Notes V-2 by Rajeev
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. It means that processed data is useful for business.
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 or database schema is written in DDL
language.
• Create: create database or Table (Column and types of data in column, size
of data) e.g. Roll_no int(3)- it means roll no should be integer of 3 digits
value, Name varchar(20)- it means Name should be character of maximum
20 character length.
• 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. It means that through a simple or small program code you
can get/update data from/of database as per requirement. Which is in another way
“ Manipulation and Processing of database”.
• Select: fetch data from database. --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.
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:
Basic/Fundamental Operations:
1.Select* (σ)
• fetch rows (tuples) from table(relation) which satisfies a given condition.
Ex: σage > 17 (Student) --It will fetch the tuples(rows) from table Student, for
which age will be greater than 17.
2. Project** (∏)
• project only a certain set of attributes of a relation.
Ex: - ∏Name, Age(Student)--Result relation with attribute name and Age
only.
3. Union (∪)
• fetch data from two relations(tables)
• duplicate tuples are automatically eliminated from the result.
Ex: - ∏Student(RegularClass) ∪ ∏Student(ExtraClass)
4. Set Difference (-)
• used to find data present in one relation and not present in the second
relation.
Ex:- ∏Student(RegularClass) - ∏Student(ExtraClass)--It will result relation
with name of students who attend the regular class but not the extra class.
5. Cartesian product (X)
• combine data from two different relations(tables)
Ex:- σtime = 'morning' (RegularClass X ExtraClass) --- result information for
Regular Class and Extra Class which are conducted during morning.
6. Rename (ρ)
• Rename output relation from operation select, project, union, set
difference, cartesian.
Ex:- ρ(STUDENT1, STUDENT)
Hashing**:
Student StudentCourse
Types:
1. Inner Join
• Simplest Join
• Return records that have matching values in both tables.
SELECT StudentCourse.COURSE_ID, Student.NAME, Student.AGE FROM Student
ON Student.ROLL_NO = StudentCourse.ROLL_NO;
4. Full Join
• returns all records from the right table and left table.
Name Course_ID
Harsh 1
Pratik 2
Riyanka 2
Deep 3
Saptarhi 1
Dhanraj Null
Rohit Null
Niraj Null
Null 4
Null 5
Null 4
5. Self Join:
• is a type of join that combines the records of a table with itself.