100% found this document useful (1 vote)
433 views

Dbms Lab Manual

The document describes the schema and sample data for an educational institution database with tables for Students, Faculty, Classes, and student Enrollments. It includes the DDL to create the tables, sample data inserts, and queries to retrieve information from the tables. The goals are to model student and class data, as well as the relationships between them, to help administrators and faculty access relevant information.

Uploaded by

Chiranth BO
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
433 views

Dbms Lab Manual

The document describes the schema and sample data for an educational institution database with tables for Students, Faculty, Classes, and student Enrollments. It includes the DDL to create the tables, sample data inserts, and queries to retrieve information from the tables. The goals are to model student and class data, as well as the relationships between them, to help administrators and faculty access relevant information.

Uploaded by

Chiranth BO
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 44

Dept of CSE

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

DBMS Lab Manual

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

Steps to Login to SQL prompt to run the appropriate scripts


DBMS Lab Manual

Dept of CSE

CBIT

1. Go to windows desktop.

2. Click Programs->Oracle-OraDb11g_home2->Application Development -> SQL plus

3. Click sqlPlus

DBMS Lab Manual

Dept of CSE

CBIT

4. Enter username as system and password as hpserver

DBMS Lab Manual

Dept of CSE

CBIT

1.Educational
Institution Database

1.1 Experiment Specification

DBMS Lab Manual

Dept of CSE

CBIT

1. Consider the following relations:


Student(snum: integer, sname: string, major: string, level: string, age: integer)
Class(name: string, meets at: string, room: string, d: integer)
Enrolled(snum:integer, cname:string)
Faculty(fid:integer,fname:string,deptid: integer)
The meaning of these relations is straightforward. For example, enrolled has one record
per student-class pair such that the student is enrolled in the class. Level is a two
character code with 4 different values (Example: Junior: JR etc)
Write the following queries in SQL. No duplicates should be printed in any of the
answers.
i.
ii.
iii.
iv.
v.

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.

1.2 Creation of empty tables


SQL> create table Student(
2 snum integer not null,
3 sname varchar(25),
4 major varchar(25),
5 levl char(2),
6 age integer,
7 primary key(snum));
Table created.
SQL> create table Faculty(
2 fid integer not null,
3 fname varchar(25),
4 deptid integer,
5 primary key(fid));
Table created.
SQL> create table Class(

DBMS Lab Manual

Dept of CSE
2
3
4
5
6
7

CBIT

name varchar(15) not null,


meetsat varchar(50),
room varchar(15),
d integer,
primary key(name),
foreign key (d) references Faculty(fid));

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

NOT NULL NUMBER(38)


VARCHAR2(25)
VARCHAR2(25)
CHAR(2)
NUMBER(38)

1.4 Inserting data into tables


Run the insert script as follows:
SQL> insert into Student values(1,'Ramesh','CSE','JR',18);
1 row created.
SQL> insert into Student values(2,'Suresh','CSE','JR',18);
1 row created.
SQL> insert into Student values(3,'Vijay','CSE','SR',19);

DBMS Lab Manual

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.

DBMS Lab Manual

Dept of CSE

CBIT

1.3 Checking the creation of tables


SQL> desc faculty;
Name
Null? Type
----------------------------------------- -------- ---------------------------FID
FNAME
DEPTID

NOT NULL NUMBER(38)


VARCHAR2(25)
NUMBER(38)

1.4 Inserting data into tables


Run the insert script as follows:
SQL> insert into Faculty values(1,'Prof.Harshith',1);
1 row created.
SQL> insert into Faculty values(2,'Prof.Mathew',1);
1 row created.
SQL> insert into Faculty values(3,'AsstProf.Kandasamy',2);
1 row created.
SQL> insert into Faculty values(4,'SrLect.Prem',2);
1 row created.
1.5 Checking data insertion into tables
SQL> select * from Faculty;
FID FNAME
DEPTID
---------- ------------------------- ---------1 Prof.Harshith
1
2 Prof.Mathew
1
3 AsstProf.Kandasamy
2
4 SrLect.Prem
2

1.3 Checking the creation of tables

DBMS Lab Manual

Dept of CSE

CBIT

SQL> desc Class;


Name
Null? Type
----------------------------------------- -------- ---------------------------NAME
MEETSAT
ROOM
D

NOT NULL VARCHAR2(15)


VARCHAR2(50)
VARCHAR2(15)
NUMBER(38)

1.4 Inserting data into tables


Run the insert script as follows:
SQL> insert into Class values('JAVA','9AM','R100',1);
1 row created.
SQL> insert into Class values('C','10AM','R128',1);
1 row created.
SQL> insert into Class values('C++','10AM','R128',1);
1 row created.
SQL> insert into Class values('.NET','11AM','R201',1);
1 row created.
SQL> insert into Class values('SQL','2PM','R201',2);
1 row created.
SQL> insert into Class values('CCNA','3PM','R201',3);
1 row created.
SQL> insert into Class values('LINUX','4PM','R201',4);
1 row created.

1.5 Checking data insertion into tables

DBMS Lab Manual

10

Dept of CSE

CBIT

SQL> select * from class;


NAME
MEETSAT
--------------- -------------------------------------------------ROOM
D
--------------- ---------JAVA
9AM
R100
1
C
R128
C++
R128

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.

1.3 Checking the creation of tables

DBMS Lab Manual

11

Dept of CSE

CBIT

SQL> desc enrolled;


Name
Null? Type
----------------------------------------- -------- ---------------------------SNUM
CNAME

NOT NULL NUMBER(38)


NOT NULL VARCHAR2(15)

1.4 Inserting data into tables


Run the insert script as follows:
SQL> insert into Enrolled values(1,'JAVA');
1 row created.
SQL> insert into Enrolled values(2,'JAVA');
1 row created.
SQL> insert into Enrolled values(1,'C');
1 row created.
SQL> insert into Enrolled values(2,'C');
1 row created.
SQL> insert into Enrolled values(3,'C');
1 row created.
SQL> insert into Enrolled values(4,'C');
1 row created.
SQL> insert into Enrolled values(5,'C');
1 row created.
SQL> insert into Enrolled values(4,'C++');
1 row created.
SQL> insert into Enrolled values(5,'C++');
1 row created.

DBMS Lab Manual

12

Dept of CSE

CBIT

SQL> insert into Enrolled values(6,'.NET');


1 row created.
SQL> insert into Enrolled values(7,'SQL');
1 row created.
SQL> insert into Enrolled values(8,'CCNA');
1 row created.
SQL> insert into Enrolled values(9,'LINUX');
1 row created.
SQL> insert into Enrolled values(10,'CCNA');
1 row created.
1.5 Checking data insertion into tables
SQL> select * from enrolled;
SNUM CNAME
---------- --------------1 JAVA
2 JAVA
1C
2C
3C
4C
5C
4 C++
5 C++
6 .NET
7 SQL
SNUM CNAME
---------- --------------8 CCNA
9 LINUX
10 CCNA
14 rows selected.

DBMS Lab Manual

13

Dept of CSE

1.6

CBIT

Queries

1.6.1 1[i] Junior Student Names


Find the names of all juniors (level = JR) who are enrolled in a class taught by Prof.
Harshith.
SQL> select distinct s.sname
2 from Student s, Class c, Enrolled e, Faculty f
3 where f.fid = c.d
4 and c.name = e.cname
5 and e.snum = s.snum
6 and f.fname = 'Prof.Harshith'
7 and s.levl = 'JR' ;
SNAME
------------------------Suresh
Ramesh
1.6.2 1[ii] Class Names
Find the names of all classes that either meet in room R128 or have five or more students
enrolled.
SQL> select c.name
2 from Class c
3 where c.room='R128'
4 or c.name in (select e.cname
5
from Enrolled e
6
group by e.cname
7
having count(e.snum)>=5);
NAME
--------------C
C++
1.6.3 1[iii] Student Names
Find the names of all students who are enrolled in two classes that meet at the same time.
SQL> select distinct s.sname
2 from Student s, Enrolled e
3 where s.snum=e.snum
4 and e.cname in
5 (select c1.name
6 from Class c1, Class c2

DBMS Lab Manual

14

Dept of CSE

CBIT

7 where c1.name <> c2.name


8 and c1.meetsat = c2.meetsat);
SNAME
------------------------Santosh
Pradeep
Ramesh
Suresh
Vijay
1.6.4 1[iv] Faculty Members-Every room
Find the names of faculty members who teach in every room in which some class is
taught.
SQL> select fname from Faculty where fid = (select d from Class c1 group by d ha
ving count(distinct room) = (select count(distinct room) from Class c2));
FNAME
------------------------Prof.Harshith
1.6.5 1[v] Faculty Members-Combined enrollment
Find the names of faculty members for whom the combined enrollment of the courses
that they teach is less than 5.
SQL> select distinct fname from Faculty where fid in (select d from Class group
by d having count(distinct name) < 5)
2 union
3 select distinct f.fname from Faculty f
4 where not exists (select c1.name from Class c1 where c1.d =f.fid);
FNAME
------------------------AsstProf.Kandasamy
Prof.Harshith
Prof.Mathew
SrLect.Prem

DBMS Lab Manual

15

Dept of CSE

CBIT

2.Flight Airlines
Database

2.1 Experiment specification

DBMS Lab Manual

16

Dept of CSE

CBIT

2. The following relations keep track of airline flight information:


Flights (no: integer, from: string, to: string, distance: integer, Departs: time, arrives:
time, price: real)
Aircraft (aid: integer, aname: string, cruisingrange: integer)
Certified(eid: integer, aid: integer)
Employees(eid:integer, ename: string, salary: integer)
Note that the Employees relation describes pilots and other kinds of employees as well.
Every pilot is certified for some aircraft, and only pilots are certified to fly.
Write each of the statements in SQL.
i)
ii)
iii)
iv)
v)
vi)

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.

2.2 Creation of empty tables


SQL> create table Aircraft(
2 aid integer not null,
3 aname varchar(25),
4 cruisingrange integer,
5 primary key (aid));
Table created.
SQL> create table Flights(
2 no integer not null,
3 frm varchar(25),
4 too varchar(25),
5 distance integer,
6 departs date,
7 arrives date,
8 price float,
9 primary key (no),
10 foreign key (no) references Aircraft(aid));
Table created.

DBMS Lab Manual

17

Dept of CSE

CBIT

SQL> create table Employees(


2 eid integer not null,
3 ename varchar(25),
4 salary integer,
5 primary key (eid));
Table created.
SQL> create table Certified(
2 eid integer,
3 aid integer,
4 primary key (eid,aid),
5 foreign key (eid) references Employees(eid),
6 foreign key (aid) references Aircraft(aid));
Table created.
2.3
Checking the creation of tables
SQL> desc Aircraft;
Name
Null? Type
----------------------------------------- -------- ---------------------------AID
ANAME
CRUISINGRANGE
2.4

NOT NULL NUMBER(38)


VARCHAR2(25)
NUMBER(38)

Inserting data into tables

SQL> insert into Aircraft values(100,'British Airways',1030);


1 row created.
SQL> insert into Aircraft values(200,'Luftansa',928);
1 row created.
SQL> insert into Aircraft values(300,'Boeing Airlines',829);
1 row created.
SQL> insert into Aircraft values(400,'Indian Airlines',731);
1 row created.
SQL> insert into Aircraft values(500,'UAE Airlines',950);

DBMS Lab Manual

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

Checking the creation of tables

SQL> desc Flights;


Name
Null? Type
----------------------------------------- -------- ---------------------------NO
FRM
TOO
DISTANCE
DEPARTS
ARRIVES
PRICE

NOT NULL NUMBER(38)


VARCHAR2(25)
VARCHAR2(25)
NUMBER(38)
DATE
DATE
FLOAT(126)

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);

DBMS Lab Manual

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;

DBMS Lab Manual

20

Dept of CSE

CBIT

Name
Null? Type
----------------------------------------- -------- ---------------------------EID
ENAME
SALARY

NOT NULL NUMBER(38)


VARCHAR2(25)
NUMBER(38)

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

Checking the creation of tables

DBMS Lab Manual

21

Dept of CSE

CBIT

SQL> desc Certified;


Name
Null? Type
----------------------------------------- -------- ---------------------------EID
AID

NOT NULL NUMBER(38)


NOT NULL NUMBER(38)

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);

DBMS Lab Manual

22

Dept of CSE

CBIT

1 row created.
SQL> insert into Certified values(5,500);
1 row created.
2.5

Checking data insertion into tables

SQL> select * from certified;


EID
AID
---------- ---------1
100
2
100
3
100
1
200
1
300
1
400
2
200
2
300
2
400
4
500
5
500
11 rows selected.
2.6

Queries

2.6.1 2[i] Aircraft Names


Find the names of aircraft such that all pilots certified to operate them have salaries more
than Rs 80000
SQL> select distinct A.aname
2 from Aircraft A, Certified C1, Employees E1
3 where E1.eid = C1.eid
4 and C1.aid = A.aid
5 and A.aid IN (select distinct C2.aid
6
from Certified C2, Employees E2
7
where C2.eid = E2.eid
8
and E2.salary > 80000);
ANAME
------------------------UAE Airlines
British Airways
Luftansa

DBMS Lab Manual

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

SQL> select C2.eid, max(A.Cruisingrange)


2 from Certified C2, Aircraft A
3 where A.aid = C2.aid
4 and C2.eid in (select C1.eid from Certified C1 group by C1.eid having count
(C1.eid)>3)
5 group by C2.eid;
EID MAX(A.CRUISINGRANGE)
---------- -------------------1
1030
2
1030
2.6.3 2[iii] Pilot Names
Find the names of the pilots whose salary is less than the price of the cheapest route from
Bengaluru to Frankfurt.
SQL> select ename from Employees where salary < (select min(price) from Flight
where frm='Bengaluru' and too='Frankfurt');
ENAME
------------------------William J. Abrahams
Martin Adams
2.6.4 2[iv] 1000 KM Cruising Range
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.
SQL> select A.aid, avg(E.salary)
2 from Aircraft A, Certified C, Employees E
3 where A.aid = C.aid
4 and C.eid = E.eid
5 and A.cruisingrange>1000
6 group by A.aid;
AID AVG(E.SALARY)
---------- ------------100
90000
2.6.5 2[v] Pilot Names-Boeing

DBMS Lab Manual

24

Dept of CSE

CBIT

Find the names of pilots certified for some Boeing aircraft.


SQL> select distinct E.ename from Aircraft A, Certified C, Employees E where E.e
id = C.eid and C.aid = A.aid and A.aname like 'Boeing%';
ENAME
------------------------William J. Abrahams
Martin Adams
2.6.6 2[vi] Aircraft Aids
Find the aids of all aircraft that can be used on routes from Bengalaru to NewDelhi.
SQL> select no from Flights where frm='Bengaluru' and too='NewDelhi';
NO
---------300
400

DBMS Lab Manual

25

Dept of CSE

CBIT

3.STUDENT
DATABASE

3.1

Experiment specification

DBMS Lab Manual

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));

DBMS Lab Manual

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');

DBMS Lab Manual

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.

DBMS Lab Manual

29

Dept of CSE

CBIT

SQL> insert into Text values(4400,'C Programming','TMH','Balaguruswamy');


1 row created.
SQL> insert into Text values(5566,'Computer Nw','PHI','Tennenbaum');
1 row created.
SQL> insert into Text values(3388,'MP','PHI','Brey');
1 row created.
SQL> insert into Book_adoption values(11,3,7722);
1 row created.
SQL> insert into Book_adoption values(22,4,7722);
1 row created.
SQL> insert into Book_adoption values(11,5,4400);
1 row created.
SQL> insert into Book_adoption values(11,8,5566);
1 row created.
SQL> insert into Book_adoption values(55,4,3388);
1 row created.
SQL> insert into Book_adoption values(44,4,5566);
1 row created.
SQL> insert into Book_adoption values(44,7,3388);
1 row created.
3.1.3 3[iii] New Text Book Addition Query
Demonstrate how you add a new text book to the database and make this book be adopted
by some department
SQL> insert into Text values(1234,'Elec.Circuits','Sapna','Giridhar');

DBMS Lab Manual

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

DBMS Lab Manual

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)

DBMS Lab Manual

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,

DBMS Lab Manual

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');

DBMS Lab Manual

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.

DBMS Lab Manual

35

Dept of CSE

CBIT

SQL> insert into Catalg values(789,'VB6',2000,11,2,2000,300);


1 row created.
SQL> insert into Catalg values(213,'Frontpage2002',4000,44,5,2003,500);
1 row created.
SQL> insert into Catalg values(879,'ADA',1000,33,4,2001,195);
1 row created.
SQL> insert into Order_details values(112,123,100);
1 row created.
SQL> insert into Order_details values(113,123,20);
1 row created.
SQL> insert into Order_details values(114,213,50);
1 row created.
SQL> insert into Order_details values(115,789,500);
1 row created.
SQL> insert into Order_details values(116,879,8);
1 row created.
4.1.3 4[iii] Authors books >=2, price > avg, Published year > 2000
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.
SQL> select C.Authorid,A.Aname
2 from Catalg C,Author A
3 where A.Authorid=C.Authorid and C.Year>2000
4 and C.Price > (Select Avg(Price) from Catalg)
5 group by C.Authorid,A.Aname
6 having count(C.Authorid)>=2;
AUTHORID ANAME
---------- ---------------

DBMS Lab Manual

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

4.1.5 4[v] Price hike by 10% Query


Demonstrate how you increase the price of books published by a specific publisher by
10%
SQL> update Catalg
2 set price=price*1.10
3 where publisherid=33;
2 rows updated.

DBMS Lab Manual

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)

DBMS Lab Manual

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),

DBMS Lab Manual

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.

DBMS Lab Manual

40

Dept of CSE

CBIT

SQL> insert into accnt values('123','Jayanagar','25000');


1 row created.
SQL> insert into accnt values('156','Jayanagar','30000');
1 row created.
SQL> insert into accnt values('456','Basavanagudi','15000');
1 row created.
SQL> insert into accnt values('789','Noida','25000');
1 row created.
SQL> insert into accnt values('478','Marinedrive','48000');
1 row created.
SQL> insert into accnt values('778','GreenPark','60000');
1 row created.
SQL> insert into accnt values('189','Basavanagudi','48888');
1 row created.
SQL> insert into custmer values('Ramu','Jayanagar','Bangalore');
1 row created.
SQL> insert into custmer values('Kumar','Basavanagudi','Bangalore');
1 row created.
SQL> insert into custmer values('John','Noida','Newdelhi');
1 row created.
SQL> insert into custmer values('Mike','Marinedrive','Mumbai');
1 row created.
SQL> insert into custmer values('Sachin','GreenPark','NewDelhi');

DBMS Lab Manual

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.

DBMS Lab Manual

42

Dept of CSE

CBIT

SQL> insert into loan values('5555','GreenPark','7500000');


1 row created.
SQL> insert into borrower values('Ramu',1111);
1 row created.
SQL> insert into borrower values('Kumar',2222);
1 row created.
SQL> insert into borrower values('John',3333);
1 row created.
SQL> insert into borrower values('Mike',4444);
1 row created.
SQL> insert into borrower values('Sachin',5555);
1 row created.
5.1.3 5[iii] Customers having atleast 2 accounts Query
Find all the customers who have atleast two accounts at the main branch.
SQL> select customername
2 from depositor D,accnt A
3 where D.accountno=A.accountno
4 and branchname='Jayanagar'
5 group by customername
6 having count(D.accountno)>=2;
CUSTOMERNAME
--------------Ramu

5.1.4 5[iv] Customers having accounts at all branches Query


Find all the customers who have an account at all the branches located in a specified city.

DBMS Lab Manual

43

Dept of CSE

CBIT

SQL> select customername


2 from branch B,accnt A,depositor D
3 where B.branchname=A.branchname
4 and A.accountno=D.accountno
5 and B.branchcity='Bangalore'
6 group by customername
7 having count(distinct B.branchname)=(select count(distinct branchname) from
branch where branchcity='Bangalore');
CUSTOMERNAME
--------------Ramu
5.1.5 5[v] Data deletion of accounts in every branch
Demonstrate how you delete all account tuples at every branch located in a specified city
SQL> delete from accnt
2 where branchname in (select distinct B.branchname
3
from branch B
4
where branchcity is not NULL) ;
7 rows deleted.

DBMS Lab Manual

44

You might also like