Dbms Lab Manual
Dbms Lab Manual
CBIT
CONTENTS SHEET
SlNo
PageNo
1. Educational Database6
1.1 Experiment Specification..7
1.2 Creation of empty tables....7
1.3 Checking the creation of tables8,10,11,13
1.4 Inserting data into tables..8.10,11,13
1.5 Checking data insertion into tables..9,10,12,14
1.6 Queries. 15
1.6.1 1[i] Junior Student Names 15
1.6.2 1[ii] Class Names.. 15
1.6.3 1[iii] Student Names. 15
1.6.4 1[iv] Faculty Members-Every room..16
1.6.5 1[v] Faculty Members-Combined enrollment...16
2. Flight Airlines Database...17
2.1 Experiment Specification..18
2.2 Creation of empty tables...18
2.3 Checking the creation of tables..19,20,22,23
2.4 Inserting data into tables19,20,22,23
2.5 Checking data insertion into tables20,21,22,24
2.6 Queries. 24
2.6.1 2[i] Aircraft Names .. 24
2.6.2 2[ii] Maximum Cruising Range.25
2.6.3 2[iii] Pilot Names . 25
2.6.4 2[iv] 1000 KM Cruising Range 25
2.6.5 2[v] Pilot Names-Boeing ..................................26
2.6.6 2[vi] Aircraft aids..26
3. Student Database.27
3.1 Experiment Specification..28
3.1.1 3[i] Tables Creation with Keys..28
3.1.2 3[ii] Data insertion 5 rows.29
3.1.3 3[iii] New Text Book Addition Query..31
3.1.4 3[iv] CS department Text Books Query32
3.1.5 3[v] Specific Publisher Text Book Query..32
4. Book Dealer Database.36
4.1 Experiment Specification.37
4.1.1 4[i] Tables creation with keys...37
4.1.2 4[ii] Data insertion 5 rows.38
4.1.3 4[iii] Authors books >=2, price > avg, Published year > 200040
Dept of CSE
4.1.4
4.1.5
CBIT
4[iv] Author of max sales books Query.41
4[v] Price hike by 10% Query...41
5. Banking Database45
5.1 Experiment Specification..46
5.1.1 5[i] Tables creation with keys46
5.1.2 5[ii] Data insertion 5 rows.47
5.1.3 5[iii] Customers having atleast 2 accounts Query.50
5.1.4 5[iv] Customers having accounts at all branches Query...51
5.1.5 5[v] Data deletion of accounts in every branch51
Dept of CSE
CBIT
1. Go to windows desktop.
3. Click sqlPlus
Dept of CSE
CBIT
Dept of CSE
CBIT
1.Educational
Institution Database
Dept of CSE
CBIT
Find the names of all juniors (level = JR) who are enrolled in a class taught by
Prof. Harshith
Find the names of all classes that either meet in room R128 or have five or
more students enrolled
Find the names of all students who are enrolled in two classes that meet at the
same time.
Find the names of faculty members who teach in every room in which some
class is taught.
Find the names of faculty members for whom the combined enrollment of the
courses that they teach is less than 5.
Dept of CSE
2
3
4
5
6
7
CBIT
Table created.
SQL> create table Enrolled(
2 snum integer,
3 cname varchar(15),
4 primary key(snum,cname),
5 foreign key (snum) references Student(snum),
6 foreign key (cname) references Class(name));
Table created.
1.3 Checking the creation of tables
SQL> desc Student;
Name
Null? Type
----------------------------------------- -------- ---------------------------SNUM
SNAME
MAJOR
LEVL
AGE
Dept of CSE
CBIT
1 row created.
SQL> insert into Student values(4,'Santosh','CSE','M1',20);
1 row created.
SQL> insert into Student values(5,'Pradeep','CSE','M2',21);
1 row created.
SQL> insert into Student values(6,'Antony','ISE','M2',18);
1 row created.
SQL> insert into Student values(7,'Ranjani','ISE','M2',18);
1 row created.
SQL> insert into Student values(8,'Swati','ISE','M2',19);
1 row created.
SQL> insert into Student values(9,'Anapoorna','ISE','M1',20);
1 row created.
SQL> insert into Student values(10,'Roopa','ISE','M1',21);
1 row created.
1.5 Checking data insertion into tables
SQL> select * from Student;
SNUM SNAME
MAJOR
LE
AGE
---------- ------------------------- ------------------------- -- ---------1 Ramesh
CSE
JR
18
2 Suresh
CSE
JR
18
3 Vijay
CSE
SR
19
4 Santosh
CSE
M1
20
5 Pradeep
CSE
M2
21
6 Antony
ISE
M2
18
7 Ranjani
ISE
M2
18
8 Swati
ISE
M2
19
9 Anapoorna
ISE
M1
20
10 Roopa
ISE
M1
21
10 rows selected.
Dept of CSE
CBIT
Dept of CSE
CBIT
10
Dept of CSE
CBIT
10AM
1
10AM
1
NAME
MEETSAT
--------------- -------------------------------------------------ROOM
D
--------------- ---------.NET
11AM
R201
1
SQL
R201
CCNA
R201
2PM
2
3PM
3
NAME
MEETSAT
--------------- -------------------------------------------------ROOM
D
--------------- ---------LINUX
4PM
R201
4
7 rows selected.
11
Dept of CSE
CBIT
12
Dept of CSE
CBIT
13
Dept of CSE
1.6
CBIT
Queries
14
Dept of CSE
CBIT
15
Dept of CSE
CBIT
2.Flight Airlines
Database
16
Dept of CSE
CBIT
Find the names of aircraft such that all pilots certified to operate them
have salaries more than Rs 80000
For each pilot who is certified for more than three aircrafts find the eid
and the maximum cruisingrange of the aircraft for which he or she is
certified.
Find the names of the pilots whose salary is less than the price of the
cheapest route from Bengaluru to Frankfurt.
For all aircraft with cruisingrange over 1000 kms find the name of the
aircraft and the average salary of all pilots certified for this aircraft.
Find the names of pilots certified for some Boeing aircraft.
Find the aids of all aircraft that can be used on routes from Bengalaru to
NewDelhi.
17
Dept of CSE
CBIT
18
Dept of CSE
CBIT
1 row created.
2.5 Checking data insertion into tables
SQL> select * from Aircraft;
AID ANAME
CRUISINGRANGE
---------- ------------------------- ------------100 British Airways
1030
200 Luftansa
928
300 Boeing Airlines
829
400 Indian Airlines
731
500 UAE Airlines
950
2.3
2.4
Inserting data into tables
SQL> insert into Flights values(100,'Bengaluru','Frankfurt', 7422,to_date('1900:
01:01:10:00:00', 'YYYY:MM:DD:HH24:MI:SS'),to_date('1900:01:01:20:00:00',
'YYYY:MM:DD:HH24:MI:SS'),100000);
1 row created.
SQL> insert into Flights values(200,'Bengaluru','Frankfurt', 7422,to_date('1900:
01:01:12:00:00', 'YYYY:MM:DD:HH24:MI:SS'),to_date('1900:01:01:22:00:00',
'YYYY:MM:DD:HH24:MI:SS'),91000);
1 row created.
SQL> insert into Flights values(300,'Bengaluru','NewDelhi', 1754,to_date('1900:0
1:01:14:00:00', 'YYYY:MM:DD:HH24:MI:SS'),to_date('1900:01:02:02:00:00',
'YYYY:MM:DD:HH24:MI:SS'),150000);
19
Dept of CSE
CBIT
1 row created.
SQL> insert into Flights values(400,'Bengaluru','NewDelhi', 1754,to_date('1900:0
1:01:15:00:00', 'YYYY:MM:DD:HH24:MI:SS'),to_date('1900:01:02:03:00:00',
'YYYY:MM:DD:HH24:MI:SS'),145000);
1 row created.
SQL> insert into Flights values(500,'London','Dubai', 3000,to_date('1900:01:01:1
6:00:00', 'YYYY:MM:DD:HH24:MI:SS'),to_date('1900:01:02:04:00:00',
'YYYY:MM:DD:HH24:MI:SS'),145000);
1 row created.
2.5
Checking data insertion into tables
SQL> select * from Flights;
NO FRM
TOO
DISTANCE
---------- ------------------------- ------------------------- ---------DEPARTS ARRIVES
PRICE
--------- --------- ---------100 Bengaluru
Frankfurt
7422
01-JAN-00 01-JAN-00 100000
200 Bengaluru
01-JAN-00 01-JAN-00
Frankfurt
91000
7422
300 Bengaluru
01-JAN-00 02-JAN-00
NewDelhi
150000
1754
NO FRM
TOO
DISTANCE
---------- ------------------------- ------------------------- ---------DEPARTS ARRIVES
PRICE
--------- --------- ---------400 Bengaluru
NewDelhi
1754
01-JAN-00 02-JAN-00 145000
500 London
01-JAN-00 02-JAN-00
Dubai
145000
3000
2.3
Checking the creation of tables
SQL> desc Employees;
20
Dept of CSE
CBIT
Name
Null? Type
----------------------------------------- -------- ---------------------------EID
ENAME
SALARY
2.4
Inserting data into tables
SQL> insert into Employees values (1,'William J. Abrahams', 85000)
1 row created.
SQL> insert into Employees values (2,'Martin Adams', 90000);
1 row created.
SQL> insert into Employees values (3,'Richard H. Arnold', 95000);
1 row created.
SQL> insert into Employees values (4,'Antony', 120000);
1 row created.
SQL> insert into Employees values (5,'John', 150000);
1 row created.
2.5
Checking data insertion into tables
SQL> select * from employees;
EID ENAME
SALARY
---------- ------------------------- ---------1 William J. Abrahams
85000
2 Martin Adams
90000
3 Richard H. Arnold
95000
4 Antony
120000
5 John
150000
2.3
21
Dept of CSE
CBIT
2.4
Inserting data into tables
SQL> insert into Certified values(1,100);
1 row created.
SQL> insert into Certified values(2,100);
1 row created.
SQL> insert into Certified values(3,100);
1 row created.
SQL> insert into Certified values(1,200);
1 row created.
SQL> insert into Certified values(1,300);
1 row created.
SQL> insert into Certified values(1,400);
1 row created.
SQL> insert into Certified values(2,200);
1 row created.
SQL> insert into Certified values(2,300);
1 row created.
SQL> insert into Certified values(2,400);
1 row created.
SQL> insert into Certified values(4,500);
22
Dept of CSE
CBIT
1 row created.
SQL> insert into Certified values(5,500);
1 row created.
2.5
Queries
23
Dept of CSE
CBIT
Boeing Airlines
Indian Airlines
2.6.2 2[ii] Maximum Cruising Range
For each pilot who is certified for more than three aircrafts find the eid
maximum cruisingrange of the aircraft for which he or she is certified.
and the
24
Dept of CSE
CBIT
25
Dept of CSE
CBIT
3.STUDENT
DATABASE
3.1
Experiment specification
26
Dept of CSE
CBIT
3. consider the following database of student enrollment in courses and books adopted for
each course
STUDENT(regno:string,name:string,major:string,bdate:date)
COURSE(course:int,cname:string,dept:string)
ENROLL(regno:string,course:int,marks:int)
BOOK_ADOPTION(course:int,sem:int,book-ISBN:int)
TEXT(book-ISBN:int,book-title:string,publisher:string,author:string)
i. create the above tables by properly specifying the primary keys and foreign keys
ii. enter five tuples for each relation
iii. demonstrate how you add a new text book to the database and make this book be
adopted by some department
iv. produce a list of text books in alphabetical order for courses offered by CS
department that use more than two books
v. list any department that has all its adopted books published by a specific publisher
vi. generation of suitable reports
vii. create suitable front end for querying and displaying the results
3.1.1 3[i] Tables creation with keys
Create the above tables by properly specifying the primary keys and foreign keys
SQL> create table Student(
2 Regno varchar(10),
3 Name varchar(10) not null,
4 Major varchar(10) not null,
5 Bdate date,
6 primary key (Regno));
Table created.
SQL> create table Course(
2 Courseno integer,
3 Cname varchar(10) not null,
4 Dept varchar(10) not null,
5 primary key (Courseno));
Table created.
SQL> create table Enroll(
2 Regno varchar(10),
3 Courseno integer,
4 Sem integer not null,
5 Marks integer,
6 primary key (Regno,Courseno),
7 foreign key (Regno) references Student(Regno),
8 foreign key (Courseno) references Course(Courseno));
27
Dept of CSE
CBIT
Table created.
SQL> create table Text(
2 ISBN integer,
3 Booktitle varchar(20) not null,
4 Publisher varchar(20),
5 Author varchar(15),
6 primary key (ISBN));
Table created.
SQL> create table Book_adoption(
2 Courseno integer,
3 Sem integer,
4 ISBN integer,
5 primary key (Courseno,Sem),
6 foreign key (Courseno) references Course(Courseno),
7 foreign key (ISBN) references Text(ISBN));
Table created.
3.1.2 3[ii] Data insertion 5 rows
Enter five tuples for each relation
SQL> insert into Student values('1BI02CS010','Karan','CSE','02-Jan-1984');
1 row created.
SQL> insert into Student values('1BI02EE015','Jack','EEE','15-Apr-1983');
1 row created.
SQL> insert into Student values('1BI00CS010','Adi','CSE','02-Jan-1982');
1 row created.
SQL> insert into Student values('1BI01EC089','Rahul','ECE','01-Dec-1983');
1 row created.
SQL> insert into Student values ('1BI01ME075','Sachin','MECH','18-Jul-1983');
1 row created.
SQL> insert into Course values(11,'DSC','CSE');
28
Dept of CSE
CBIT
1 row created.
SQL> insert into Course values(22,'ADA','CSE');
1 row created.
SQL> insert into Course values(33,'CN','EC');
1 row created.
SQL> insert into Course values(44,'TD','MECH');
1 row created.
SQL> insert into Course values(55,'MP','EC');
1 row created.
SQL> insert into Enroll values('1BI02CS010',22,5,72);
1 row created.
SQL> insert into Enroll values('1BI00CS010',11,3,90);
1 row created.
SQL> insert into Enroll values('1BI01EC089',33,6,52);
1 row created.
SQL> insert into Enroll values('1BI01ME075',44,4,85);
1 row created.
SQL> insert into Enroll values('1BI02EE015',22,5,75);
1 row created.
SQL> insert into Text values(7722,'VB6','Dreamtech','Holzner');
1 row created.
SQL> insert into Text values(1144,'DS with C','Sapna','Nandagopalan');
1 row created.
29
Dept of CSE
CBIT
30
Dept of CSE
CBIT
1 row created.
SQL> insert into Book_adoption values(55,3,1234);
1 row created.
3.1.4 3[iv] CS department Text Books Query
Produce a list of text books in alphabetical order for courses offered by CS department
that use more than two books
SQL> select C.Courseno,T.ISBN,T.Booktitle
2 from Course C,Book_adoption BA,Text T
3 where C.Courseno=BA.Courseno and BA.ISBN=T.ISBN and C.Dept='CSE'
4 group by C.Courseno,T.ISBN,T.Booktitle;
COURSENO
ISBN BOOKTITLE
---------- ---------- -------------------11
5566 Computer Nw
22
7722 VB6
11
4400 C Programming
11
7722 VB6
3.1.5 3[v] Specific Publisher Text Book Query
List any department that has all its adopted books published by a specific publisher
SQL> select distinct C.Dept
2 from Course C, Book_adoption A,Text T
3 where C.Courseno=A.Courseno
4 and A.ISBN=T.ISBN
5 and not exists (( select Y.ISBN
6 from Course X,Book_adoption Y
7 where X.Courseno=Y.Courseno
8 and X.Dept=C.Dept)
9 minus
10 (select ISBN
11 from Text
12 where publisher='PHI'));
DEPT
---------MECH
31
Dept of CSE
CBIT
4.BOOK DEALER
DATABASE
4.1
Experiment specification
4.The following tables are maintained by a book dealer
AUTHOR(author-id:int,name:string,city:string,country:string)
32
Dept of CSE
CBIT
PUBLISHER(publisher-id:int,name:string,city:string,country:string)
CATALOG(book-id:int,title:string,author-id:int,publisher-id:int,categoryid:int,year:int,price:int)
CATEGORY(category-id:int,description:script)
ORDER-DETAILS(order-no:int,book-id:int,quantity:int)
i. create the above details by properly specifying the primary keys and foreign keys
ii. enter atleast five tuples for each relation
iii. Give the details of the authors who have 2 or more books in the catalog and the
price of the books is greater than the average price of the books in the catalog and
the year of publication is after 2000.
iv. find the author of the book which has maximum sales
v. demonstrate how you increase the price of books published by a specific publisher
by 10%
vi. generation of suitable reports
vii. create suitable front end for querying and display the results
4.1.1 4[i] Tables creation with keys
Create the above details by properly specifying the primary keys and foreign key
SQL> create table Author(
2 Authorid integer,
3 Aname varchar(15),
4 Acity varchar(15),
5 Acountry varchar(15),
6 primary key (Authorid));
Table created.
SQL> create table Publisher(
2 Publisherid integer,
3 Pname varchar(15),
4 Pcity varchar(15),
5 Pcountry varchar(15),
6 primary key (Publisherid));
Table created.
SQL> create table Category(
2 Categoryid integer,
3 Description varchar(20),
4 primary key (Categoryid));
Table created.
SQL> create table Catalg(
2 Bookid integer,
33
Dept of CSE
CBIT
3 Title varchar(20),
4 Authorid integer,
5 Publisherid integer,
6 Categoryid integer,
7 Year integer,
8 Price integer,
9 primary key (Bookid),
10 foreign key (Authorid) references Author(Authorid),
11 foreign key (Publisherid) references Publisher(Publisherid),
12 foreign key (Categoryid) references Category(Categoryid));
Table created.
SQL> create table Order_details(
2 Orderno integer,
3 Bookid integer,
4 Quantity integer,
5 primary key (Orderno,Bookid),
6 foreign key (Bookid) references Catalg(Bookid));
Table created.
4.1.2 4[ii] Data insertion 5 rows
Enter atleast five tuples for each relation
SQL> insert into Author values(1000,'Nandagopalan','Bangalore','India');
1 row created.
SQL> insert into Author values(2000,'Tony','Haywood','USA');
1 row created.
SQL> insert into Author values(3000,'Holzner','New York','USA');
1 row created.
SQL> insert into Author values(4000,'Tennenbaum','London','UK');
1 row created.
SQL> insert into Author values(5000,'Balaguruswamy','Chennai','India');
1 row created.
SQL> insert into Publisher values(11,'Wiely','NewDelhi','India');
34
Dept of CSE
CBIT
1 row created.
SQL> insert into Publisher values(22,'PHI','California','USA');
1 row created.
SQL> insert into Publisher values(33,'Sapna','Bangalore','India');
1 row created.
SQL> insert into Publisher values(44,'TMH','NewYork','USA');
1 row created.
SQL> insert into Publisher values(55,'Wrox','Texas','USA');
1 row created.
SQL> insert into Category values(1,'OS');
1 row created.
SQL> insert into Category values(2,'Languages');
1 row created.
SQL> insert into Category values(3,'Hardware');
1 row created.
SQL> insert into Category values(4,'Algorithms');
1 row created.
SQL> insert into Category values(5,'Internet');
1 row created.
SQL> insert into Catalg values(123,'DSC',1000,33,2,2000,185);
1 row created.
SQL> insert into Catalg values(456,'Networks',4000,44,4,2002,365);
1 row created.
35
Dept of CSE
CBIT
36
Dept of CSE
CBIT
4000 Tennenbaum
4.1.4 4[iv] Author of max sales books Query
Find the author of the book which has maximum sales
SQL> create view Salesdetails as(
2 Select OD.Bookid as BookNo,C.Price Cost,sum(OD.quantity) as Qty, sum(OD.qu
ntity*C.price) as Sales
3 from Order_details OD,Catalg C,Author A
4 where OD.Bookid=C.Bookid and C.Authorid=A.Authorid
5 group by OD.Bookid,C.Price);
View created.
SQL> select A.Authorid,A.Aname,S.BookNo,S.Sales
2 from Author A,Catalg C,Salesdetails S
3 where A.Authorid=C.Authorid and S.BookNo=C.Bookid
4 and sales=(select Max(Sales) from Salesdetails);
AUTHORID ANAME
BOOKNO
---------- --------------- ---------- ---------2000 Tony
789 150000
SALES
37
Dept of CSE
CBIT
5.BANKING
DATABASE
5.1
Experiment specification
5. Consider the following database for a banking enterprise
BRANCH(branch-name:string,branch-city:string,assets:real)
38
Dept of CSE
CBIT
ACCOUNT(accno:int,branch-name:string,balance:real)
DEPOSITOR(customer-name:string,accno:int)
CUSTOMER(customer-name:string,customer-street:string,city:string)
LOAN(loan-number:int,branch-name:string,loan-number-int)
BORROWER(customer-name:string,customer-street:string,city:string)
i. create the above tables by properly specifying the primary and foreign keys
ii. enter 5 tuples for each relation
iii. find all the customers who have atleast two accounts at the main branch
iv. find all the customers who have an account at all the branches located in a
specified city
v. demonstrate how you delete all account tuples at every branch located in a
specified city
vi. genetration of suitable reports
vii. create suitable front end for querying and display the results
5.1.1 5[i] Tables creation with keys
Create the above tables by properly specifying the primary and foreign keys
SQL> create table branch(
2 branchname varchar(15),
3 branchcity varchar(15),
4 assets real,
5 primary key (branchname));
Table created.
SQL> create table accnt(
2 accountno integer,
3 branchname varchar(15),
4 balance real,
5 primary key (accountno),
6 foreign key (branchname) references branch(branchname) ON DELETE
CASCADE );
Table created.
SQL> create table depositor(
2 customername varchar(15),
3 accountno integer,
4 primary key (customername,accountno),
5 foreign key (accountno) references accnt(accountno)ON DELETE CASCADE );
Table created.
SQL> create table custmer(
2 customername varchar(15),
39
Dept of CSE
CBIT
3 customerstreet varchar(15),
4 city varchar(15),
5 primary key (customername));
Table created.
SQL> create table loan(
2 loanno integer,
3 branchname varchar(15),
4 amount real,
5 primary key (loanno),
6 foreign key (branchname) references branch(branchname) ON DELETE
CASCADE );
Table created.
SQL> create table borrower(
2 customername varchar(15),
3 loanno integer,
4 primary key (customername,loanno),
5 foreign key (customername) references custmer(customername)ON DELETE
CASCADE ,
6 foreign key (loanno) references loan(loanno)ON DELETE CASCADE );
Table created.
5.1.2 5[ii] Data insertion 5 rows
Enter 5 tuples for each relation
SQL> insert into branch values('Jayanagar','Bangalore','15000000');
1 row created.
SQL> insert into branch values('Basavanagudi','Bangalore','25000000');
1 row created.
SQL> insert into branch values('Noida','NewDelhi','50000000');
1 row created.
SQL> insert into branch values('Marinedrive','Mumbai','40000000');
1 row created.
SQL> insert into branch values('GreenPark','Newdelhi','30000000');
1 row created.
40
Dept of CSE
CBIT
41
Dept of CSE
CBIT
1 row created.
SQL> insert into depositor values('Ramu',123);
1 row created.
SQL> insert into depositor values('Ramu',156);
1 row created.
SQL> insert into depositor values('Ramu',189);
1 row created.
SQL> insert into depositor values('Kumar',456);
1 row created.
SQL> insert into depositor values('John',789);
1 row created.
SQL> insert into depositor values('Mike',478);
1 row created.
SQL> insert into depositor values('Sachin',778);
1 row created.
SQL> insert into loan values('1111','Jayanagar','250000');
1 row created.
SQL> insert into loan values('2222','Basavanagudi','350000');
1 row created.
SQL> insert into loan values('3333','Noida','150000');
1 row created.
SQL> insert into loan values('4444','Marinedrive','1500000');
1 row created.
42
Dept of CSE
CBIT
43
Dept of CSE
CBIT
44