DBMS Lab Manual
DBMS Lab Manual
LAB MANUAL
DATABASE MANAGEMENT SYSTEM
INDEX
PAGE
WEEK CONTENT
NO.
2 Relational Model
7 Normalization
Usage of Cursors
10
Course Objectives:
Introduce ER data model, database design and normalization
Learn SQL basics for data definition and data manipulation
Course Outcomes:
● Design database schema for a given application and apply normalization
● Acquire skills in using SQL commands for data definition and data
manipulation.
● Develop solutions for database applications using procedures, cursors and
triggers
List of Experiments:
Code of Conduct
Students who turn up late to the labs will in no case be permitted to perform the experiment
scheduled for the day.
After completion of the experiment, certification of the staff in-charge concerned in the
observation book is necessary.
Students should bring a notebook of about 100 pages and should enter the
readings/observations/results into the notebook while performing the experiment.
The record of observations along with the detailed experimental procedure of the experiment
performed in the immediate previous session should be submitted and certified by the staff
member in-charge.
Not more than three students in a group are permitted to perform the experiment on a set up.
The group-wise division made in the beginning should be adhered to, and no mix up of student
among different groups will be permitted later.
The components required pertaining to the experiment should be collected from Lab – in -
charge after duly filling in the requisition form.
When the experiment is completed, students should disconnect the setup made by them, and
should return all the components/instruments taken for the purpose.
Any damage of the equipment or burnout of components will be viewed seriously either by
putting penalty or by dismissing the total group of students from the lab for the semester/year.
Students should be present in the labs for the total scheduled duration.
Students are expected to prepare thoroughly to perform the experiment before coming to
Laboratory.
Procedure sheets/data sheets provided to the students’ groups should be maintained neatly
and are to be returned after the experiment.
1. Database Systems design, Implementation, and Management, Peter Rob & Carlos Coronel
7th Edition.
5. Database Systems Using Oracle: A Simplified guide to SQL and PL/SQL, Shah, PHI.
EXPERIMENT NO: 1
ER Diagram consists of some shapes which have their significance i.e. Rectangles are used
to represent the entities, Rhombus is used to represent the association between the entities,
and Oval represents the attributes of an entity.
DESCRIPTION:
EXPERIMENT NO: 2
Relational Model
Relation: Branch
Relation: Account
Relation: Customer
Relation: Depositor
Relation: Loan
Relation: Borrower
customer_id loan_number
1 1111
2 2222
3 3333
4 4444
Relation: Employee
These commands are used to create and modify the structure of the table.
2) Alter
3) Drop
4) Rename
COMMANDS:
Create:
Syntax:
Alter:
Syntax:
Drop:
Syntax:
Rename:
Syntax:
Rename<oldtablename> to <newtablename>
ENTITY: Branch
TABLE CREATION
TABLE DESCRIPTION
TABLE CREATION
drop branch_manager;
TABLE DESCRIPTION
Aurora’s Technological & Research Institute 22
Department of CSE Lab Manual
mysql > Desc branch;
ENTITY: Account
TABLE CREATION
TABLE DESCRIPTION
TABLE CREATION
drop account_type;
TABLE DESCRIPTION
ENTITY: Customer
TABLE CREATION
TABLE DESCRIPTION
TABLE CREATION
drop customer_details;
TABLE DESCRIPTION
ENTITY: Depositor
TABLE CREATION
TABLE DESCRIPTION
TABLE CREATION
drop deposit_date;
TABLE DESCRIPTION
ENTITY: Loan
TABLE CREATION
TABLE DESCRIPTION
TABLE DESCRIPTION
ENTITY: Employee
TABLE CREATION
TABLE DESCRIPTION
EXPERIMENT NO: 4
1)Insert
2)Update
3)Delete
COMMANDS:
Insert:
Syntax:
values ( );
values(1,'dhanush',19,40,40,40,40,40);
values(1,'dhanush',19,40,40,40,40,40),
(2,'ganesh',19,30,30,30,30,30);
values(1,'Karthik',40);
Update:
Syntax
Delete:
Delete command is used to delete the values of the table.
Syntax:
TUPLES DESCRIPTION
ENTITY: Account
INSERTING TUPLES
TUPLES DESCRIPTION
ENTITY: Customer
INSERTING TUPLES
TUPLES DESCRIPTION
ENTITY: Depositor
INSERTING TUPLES
Values (1,123,'2021-02-23',50000),
(2,456,'2019-10-15', 150000),
(3,789,'2023-08-01', 30000),
(4,113,'2015-07-07', 60000),
(5,118,'2010-02-04', 100000),
(6,143,'2019-10-16', 70000),
(7,731,'2018-12-10', 10000),
Aurora’s Technological & Research Institute 35
Department of CSE Lab Manual
(8,9494,'2024-01-15', 20000);
TUPLES DESCRIPTION
ENTITY: Loan
INSERTING TUPLES
values(1111,'Uppal',250000),
(2222,'Greenpark',350000),
(3333,'Jaynagar',450000),
(4444,'Noida',1500000),
(5555,'Marine drive',750000)
);
mysql > update loan set amount = 30000.00 where loan_number = 1111;
mysql > update loan set amount = 65000.00 where loan_number = 3333;
TUPLES DESCRIPTION
ENTITY: Borrower
INSERTING TUPLES
TUPLES DESCRIPTION
ENTITY: Employee
INSERTING TUPLES
values(1,'saachi',10,'Lokesh',9473627837,'2020-10-19'),
(2,'Ananya',5,'Ganesh',9467575487,'2022-11-10'),
(3,'Jaya',7,'Karthik',7339364734,'2019-02-13'),
(4,'Bhavani',2,'Shravan',9374092738,'2024-04-01'),
(5,'Sushma',4,'Himesh',9575791679,'2023-01-15');
TUPLES DESCRIPTION
EXPERIMENT NO: 5
Find the customer name and account balance amount of the depositer in the bank whose
balance is greater than 10,000.
Select c.customer, a.balance from customer c, account a,depositor d .where c.customer_id =
d.customer.id and a.account_no = d.account_no and a.balance > 10,000;
Urvasi 73848
Sai Kiran 50000
Sriman 100000
Saina 11345
Sandeep 15000
Pradeep 27000
Sahithi 49000
Nested Query:
Find the customer details who took loan amount greater than 30,00,000.
Select * from customer c where c.customer_id in(select customer_id from borrower b where
b.loan_number in(select loan_number where amount > 30,00,000));
Kumar
Sachin
Ravi
Using ANY:
TABLE DESCRIPTION
ENTITY: Boats
TABLE CREATION
TABLE DESCRIPTION
ENTITY: Reserves
TABLE CREATION
TABLE DESCRIPTION
ENTITY: Sailors
INSERTING TUPLES
values (22,'Dustin',7,45.0),
(29,'Brutus',1,33.0),
(31,'Lubber',8,55.5),
(32,'Andy',8,25.5),
(58,'Rusty',10,35.0),
(64,'Horatio',7,35.0),
(71,'Zorba',10,16.0),
(74,'Horatio',9,35.0),
(85,'Art',3,25.5),
(95,'Bob',3,63.5);
TUPLES DESCRIPTION
ENTITY: Boats
INSERTING TUPLES
values (101,'Interlake','blue'),
(102,'Interlake','red'),
(103,'Clipper','green'),
(104,'Marine','red');
TUPLES DESCRIPTION
ENTITY: Reserves
INSERTING TUPLES
values (22,101,'1998-10-10'),
(22,102,'1998-10-10');
(22,103,'1998-08-10'),
(22,104,'1998-07-10'),
(31,102,'1998-10-11'),
(31,103,'1998-06-11'),
(31,104,'1998-12-11'),
(64,101,'1998-05-09'),
(64,102,'1998-08-09'),
(74,103,'1998-08-09');
TUPLES DESCRIPTION
22 103 1998-08-10
22 104 1998-07-10
31 102 1998-10-11
31 103 1998-06-11
31 104 1998-12-11
64 101 1998-05-09
64 102 1998-08-09
74 103 1998-08-09
Queries
Dustin 45
Brutus 33
Lubber 55.5
Andy 25.5
Rusty 35
Horatio 35
Zorba 16
Art 25.5
Bob 63.5
3.Find the names of sailors who have reserved boat number 103.
mysql> select s.sname from sailors s,reserves r where s.sid=r.sid and r.bid=103;
sname
Dustin
mysql> select r.sid from boats b,reserves r where b.bid=r.bid and b.color='red';
sid
22
31
64
22
31
sname
Dustin
Lubber
Horatio
color
red
7.Find the names of sailors who have reserved at least one boat.
sname
Dustin
Lubber
Horatio
8.Find the ages of sailors hose name begins and ends with Band has atleast three characters.
age
63.5
9.Find the names of sailors who have reserved a red or a green boat.
mysql> select s.sname from sailors s,reserves r,boats b where s.sid=r.sid and r.bid=b.bid
and (b.color ='red' or b.color ='green');
sname
sname
Dustin
Lubber
Horatio
10.Find the names of sailors who have reserved both a red and a green boat.
sname
mysql> select s.sname from sailors s,reserves r,boats b where s.sid=r.sid and r.bid=b.bid and
b.color='red' intersect select s2.sname from sailors s2, b
oats b2,reserves r2 where s2.sid=r2.sid and r2.bid=b2.bid and b2.color='green';
sname
Horatio
Lubber
Dustin
11.Find all sids of sailors who have a rating of 10 or reserved boat 104.
mysql> select s.sid from sailors s where s.rating=10 union select r.sid from
reserves r where r.bid=104;
sid
58
71
22
31
Aurora’s Technological & Research Institute 51
Department of CSE Lab Manual
NESTED QUERIES
mysql> select s.sname from sailors s where s.sid in(select r.sid from reserv
es r where r.bid = 103);
sname
Dustin
Lubber
Horatio
mysql> select s.sname from sailors s where s.sid in (select r.sid from reser
ves r where r.bid in (select b.bid from boats b where b.color='red'));
sname
Dustin
Lubber
Horatio
14.Find the names of sailors who have not reserved a red boat.
mysql> select s.sname from sailors s where s.sid not in (select r.sid from
reserves r where r.bid in (select b.bid from boats b where b.color='red'));
sname
Brutus
15.Find sailors whose rating is better than some sailor called Horatio.
mysql> select s.sid from sailors s where s.rating > any (select s2.rating fr
om sailors s2 where s2.sname='Horatio');
sid
31
32
58
71
74
mysql> select s.sid from sailors s where s.rating >= all (select s2.rating f
rom sailors s2);
sid
58
EXPERIMENT NO: 6
avg(s.age)
36.9
avg(s.age)
25.5
mysql> select s.sname,s.age from sailors s where s.age=(select max(s2.age) from sailors
s2) ;
sname age
Bob 63.5
count ( * )
10
count (distinct
s.sname )
9
6.Find the names of sailors who are older than the oldest sailor with a rating of 10.
sname
Dustin
Lubber
Bob
mysql> select s.sname from sailors s where s.age > all (select s2.age from s
ailors sailors s2 where s2.rating=10);
sname
Dustin
Lubber
Bob
7.Find the age of the youngest sailor who is eligible to vote(i.e is atleast 18 years old) for
each rating level with atleast two such sailors.
rating minage
7 35
8 25.5
3 25.5
8.For each red boat, find the number of reservations for this boat.
bid reservationcount
102 3
104 2
9.Find the average age of sailors for each rating level that has atleast two sailors.
rating avgage
7 40
8 40.5
10 25.5
3 44.5
EXPERIMENT NO: 7
NORMALIZATION
NORMAL FORMS:
Student table:
Raju 24 DS English,hindi
After 1NF
Student Table:
Raju 24 DS English
A relation will be in 2NF if it is in 1NF and not contain any partial dependency i.e No
Partial Dependency.
Example: Student
Raju 24 DS English
Raju 24 DS Hindi
After 2NF
Sai 21 CSE
Shiva 22 AIML
Raju 24 DS
rollno Languages_known
21 Telugu
21 English
22 English
22 Hindi
24 English
24 Hindi
A table will be 3NF if it is in 2NF and if there is no transitive dependency for non-
prime attributes then the table is in third normal form.
After 3NF
Sai 21 CSE
Shiva 22 AIML
Ramesh 23 DS
Suresh 24 ECE
branch fee
CSE 30000
AIML 20000
DS 10000
ECE 5000
1.if it is in 3NF
Example: Student
3 Ramesh 123 DS
{rollno}{std_name} {branch_id}{branch_name}
rollno Std_name
1 Sai
2 Shiva
3 Ramesh
{rollno}{std_name}
Super Key
Branch_id Branch_name
121 CSE
122 AIML
123 DS
{branch_id}{branch_name}
Super Key
Example:
1 CSE Dancing
2 ECE Cricket
3 AIML Singing
Std_id Course
1 CSE
2 ECE
3 AIML
Std_id hobby
1 Dancing
2 Cricket
3 Singing
A relation is in fifth normal form if it is in 4NF and does not contain any join
dependency.
5NF is satisfied when all the tables present in the DBMS are broken down into as many
more tables to ensure there is no redundancy.
Example:
C Sai 1
C Shiva 1
DBMS Nagendra 3
After 5NF
Table 1
subject faculty
C Sai
C Shiva
Java Raju
DBMS Nagendra
Table 2
faculty year
Sai 1
Shiva 1
Raju 2
Nagendra 3
subject year
C 1
Java 2
DBMS 3
EXPERIMENT NO: 8
TRIGGERS
Mysql> delimiter $$
-> $$
INSERT TRIGGER
-> begin
-> end$$
UPDATE TRIGGER
-> begin
DELETE TRIGGER
-> begin
-> end$$
INPUT-OUTPUT
-> $$
acc_no amount
1 1000
2 2000
account_no operation
2 insert
total_sum
3000
acc_no amount
1 3000
2 2000
account_no operation
1 insert
2 insert
3 update
2 2000 deleted
acc_no amount
1 3000
EXPERIMENT NO: 9
values(1,'aparna',10000),
(2,'dhanush',20000),
(3,’shiva’,30000),
(4,’rakesh’,40000),
(5,’gokul’,50000)
;
1 Aparna 10000
2 Dhanush 20000
3 Shiva 30000
4 Rakesh 40000
5 Gokul 50000
mysql> delimiter $$
call emp_name(@name_list) $$
@name_list
Gokul;Rakesh;Shiva;Dhanush;Aparna;