Dbms Lab Manual 10csl57

38
Dept of IS&E VVCE DBMS Laboratory (10CSL57) 1 DATABASE MANAGEMENT SYSTEM LAB REPORT 10CSL57 DEPARTMENT OF INFORMATION SCIENCE AND ENGINEERING VIDYAVARDHAKA COLLEGE OF ENGINEERING, Mysore Prepared By: Mohammed Muddasir N,Assistant Professor Department of Information Science and Engineering VVCE, Mysore

description

DBMS, Database

Transcript of Dbms Lab Manual 10csl57

Page 1: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 1

DATABASE MANAGEMENT SYSTEM

LAB REPORT

10CSL57

DEPARTMENT OF INFORMATION SCIENCE

AND ENGINEERING

VIDYAVARDHAKA COLLEGE OF ENGINEERING,

Mysore

Prepared By: Mohammed Muddasir N,Assistant Professor

Department of Information Science and Engineering

VVCE, Mysore

Page 2: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 2

Contents 1. Student database.......................................................................................................................... 3

2. Flights Database ........................................................................................................................ 10

3. Student Enroll and Book Adaption database ............................................................................ 27

4. Book Dealer Database............................................................................................................... 31

5. Banking Database ..................................................................................................................... 35

Page 3: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 3

1. Student database

Consider the following relations:

P.K. STUDENT (snum: integer, sname: string, major: string, level: string,age: integer)

F.K.

CLASS (name: string, meets at: string, room: string, d: integer)

P.K.

ENROLLED (snum: integer, cname: string)

P.K.

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)

SQL> create table student(snum number,sname varchar2(30),major varchar2(20),levl

varchar2(2), age number, constraint st_pk_1 primary key(snum));

Table created.

SQL> create table faculty(fid number,fname varchar2(30),deptid number, constraint

fc_pk_1 primary key(fid));

Table created.

SQL> create table class(name varchar2(10),meets_at varchar2(10),room varchar2(10),fid

number, constraint cl_pk_1 primary key(name),constraint cl_fk_1 foreign key(fid)

references faculty(fid));

Table created.

SQL> create table enrolled(snum number, cname varchar2(10),

2 constraint en_pk_1 primary key(snum,cname),

3 constraint en_fk_1 foreign key(snum) references student(snum),

4 constraint en_fk_2 foreign key(cname) references class(name))

Table created.

SQL> select * from tab;

TNAME TABTYPE CLUSTERID

------------------------------ ------- ----------

CLASS TABLE

ENROLLED TABLE

FACULTY TABLE

STUDENT TABLE

Page 4: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 4

SQL> desc class;

Name Null? Type

----------------------------------------- -------- ----------------------------

NAME NOT NULL VARCHAR2(10)

MEETS_AT VARCHAR2(10)

ROOM VARCHAR2(10)

FID NUMBER

SQL> desc student;

Name Null? Type

----------------------------------------- -------- ----------------------------

SNUM NOT NULL NUMBER

SNAME VARCHAR2(30)

MAJOR VARCHAR2(20)

LEVL VARCHAR2(2)

AGE NUMBER

SQL> insert into student(snum,sname,major,levl,age) values(101,'Abhishek','CS','JR',18);

SQL> insert into student(snum,sname,major,levl,age) values(102,'Bhavya','CS','SR',18);

SQL> insert into student(snum,sname,major,levl,age) values(103,'Chandru','IS','SR',17);

SQL> insert into student(snum,sname,major,levl,age) values(104,'Diva','IS','JR',18);

SQL> insert into student(snum,sname,major,levl,age) values(105,'Vinay','IS','JR',18);

SQL> insert into student(snum,sname,major,levl,age) values(106,'Ravi','CS','SR',19);

SQL> insert into student(snum,sname,major,levl,age) values(107,'Suresh','IS','JR',18);

SQL> insert into student(snum,sname,major,levl,age) values(108,'Guru','CS','SR',18);

SQL> insert into student(snum,sname,major,levl,age) values(109,'Deva','IS','JR',17);

SQL> insert into student(snum,sname,major,levl,age) values(110,'Kiran','CS','SR',18);

SQL> insert into student(snum,sname,major,levl,age) values(111,'Kumar','CS','SR',18);

SQL> insert into student(snum,sname,major,levl,age) values(112,'Raju','CS','SR',18);

SQL> insert into student(snum,sname,major,levl,age) values(113,'Ali','CS','SR',18);

SQL> insert into student(snum,sname,major,levl,age) values(114,'Carter','IS','JR',18);

SQL> insert into student(snum,sname,major,levl,age) values(115,'Sudhir','IS','JR',18);

SQL> insert into student(snum,sname,major,levl,age) values(116,'Ilyaz','CS','SR',18);

SQL> commit;

Page 5: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 5

Commit complete.

SQL> select * from student;

SNUM SNAME MAJOR LE AGE

---------- ------------------------------ -------------------- -- ----------

101 Abhishek CS JR 18

102 Bhavya CS SR 18

103 Chandru IS SR 17

104 Diva IS JR 18

105 Vinay IS JR 18

106 Ravi CS SR 19

107 Suresh IS JR 18

108 Guru CS SR 18

109 Deva IS JR 17

110 Kiran CS SR 18

111 Kumar CS SR 18

112 Raju CS SR 18

113 Ali CS SR 18

114 Carter IS JR 18

115 Sudhir IS JR 18

116 Ilyaz CS SR 18

16 rows selected.

SQL> desc faculty;

Name Null? Type

----------------------------------------- -------- ----------------------------

FID NOT NULL NUMBER

FNAME VARCHAR2(30)

DEPTID NUMBER

SQL> insert into faculty(fid,fname,deptid) values(11,'Harshit',1);

SQL> insert into faculty(fid,fname,deptid) values(22,'Rajendra',1);

SQL> insert into faculty(fid,fname,deptid) values(33,'Muddasir',2);

SQL> insert into faculty(fid,fname,deptid) values(44,'Prashant',1);

SQL> insert into faculty(fid,fname,deptid) values(55,'Gowri',2);

SQL> commit;

SQL> select * from faculty;

FID FNAME DEPTID

---------- ------------------------------ ----------

11 Harshit 1

22 Rajendra 1

33 Muddasir 2

44 Prashant 1

55 Gowri 2

Page 6: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 6

SQL> desc class;

Name Null? Type

----------------------------------------- -------- ----------------------------

NAME NOT NULL VARCHAR2(10)

MEETS_AT VARCHAR2(10)

ROOM VARCHAR2(10)

FID NUMBER

SQL> insert into class (name,meets_at,room,fid) values('1SEM','8:30','R11',11);

SQL> insert into class (name,meets_at,room,fid) values('2SEM','9:30','R12',22)

SQL> insert into class (name,meets_at,room,fid) values('3SEM','9:30','R13',33);

SQL> insert into class (name,meets_at,room,fid) values('4SEM','10:30','R12',11)

SQL> insert into class (name,meets_at,room,fid) values('5SEM','8:30','R12',44);

SQL> insert into class (name,meets_at,room,fid) values('6SEM','11:30','R13',55);

SQL> insert into class (name,meets_at,room,fid) values('7SEM','12:30','R13',11);

SQL> insert into class (name,meets_at,room,fid) values('8SEM','10:30','R13',22);

SQL> COMMIT;

SQL> select * from class;

NAME MEETS_AT ROOM FID

---------- ---------- ---------- ----------

1SEM 8:30 R11 11

2SEM 9:30 R12 22

3SEM 9:30 R13 33

4SEM 10:30 R12 11

5SEM 8:30 R12 44

6SEM 11:30 R13 55

7SEM 12:30 R13 11

8SEM 10:30 R13 22

SQL> desc enrolled;

Name Null? Type

----------------------------------------- -------- ----------------------------

SNUM NOT NULL NUMBER

CNAME NOT NULL VARCHAR2(10)

SQL> insert into enrolled(snum,cname) values(101,'1SEM');

SQL> insert into enrolled(snum,cname) values(102,'1SEM');

SQL> insert into enrolled(snum,cname) values(103,'2SEM');

Page 7: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 7

SQL> insert into enrolled(snum,cname) values(104,'7SEM');

SQL> insert into enrolled(snum,cname) values(105,'4SEM');

SQL> insert into enrolled(snum,cname) values(106,'3SEM');

SQL> insert into enrolled(snum,cname) values(101,'5SEM');

SQL> insert into enrolled(snum,cname) values(107,'6SEM');

SQL> insert into enrolled(snum,cname) values(108,'7SEM');

SQL> insert into enrolled(snum,cname) values(109,'8SEM');

SQL> insert into enrolled(snum,cname) values(110,'4SEM');

SQL> insert into enrolled(snum,cname) values(111,'1SEM');

SQL> insert into enrolled(snum,cname) values(112,'1SEM');

SQL> insert into enrolled(snum,cname) values(113,'1SEM');

SQL> insert into enrolled(snum,cname) values(114,'1SEM');

SQL> insert into enrolled(snum,cname) values(115,'2SEM');

SQL> insert into enrolled(snum,cname) values(116,'3SEM');

SQL> commit;

SQL> select * from enrolled;

SNUM CNAME

---------- ----------

101 1SEM

102 1SEM

103 2SEM

104 7SEM

105 4SEM

106 3SEM

101 5SEM

107 6SEM

108 7SEM

109 8SEM

110 4SEM

111 1SEM

112 1SEM

113 1SEM

114 1SEM

115 2SEM

116 3SEM

Page 8: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 8

i). Find the names of all juniors(level=JR) who are enrolled in a class taught by Prof.

Harshit SQL> select s.sname

from student s,class c,enrolled e, faculty f

where s.snum=e.snum

and c.name=e.cname

and c.fid=f.fid

and s.levl='JR'

and f.fname='Harshit'

SNAME

------------------------------

Abhishek

Diva

Vinay

Carter

ii). Find the names of all classes that either meet in room R128 or have five or more

Students enrolled. SQL> select name from class

where room = 'R12'

or name in ( select cname from enrolled group by cname having count(snum)>=5);

NAME

----------

1SEM

2SEM

4SEM

5SEM

iii). Find the names of all students who are enrolled in two classes that meet at the same

time. SQL> select sname from student where snum in (

select e.snum from enrolled e,class c1,class c2 where

e.cname=c1.name

and c1.name <> c2.name

and c2.meets_at = c2.meets_at);

SNAME

------------------------------

Abhishek

Bhavya

Chandru

Diva

Vinay

Ravi

Suresh

Guru

Deva

Kiran

Kumar

Page 9: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 9

SNAME

------------------------------

Raju

Ali

Carter

Sudhir

Ilyaz

iv). Find the names of faculty members who teach in every room in which some class is

taught. SQL> select f.fname from faculty f where not exists(

select distinct c.room from class c

minus

select c1.room from class c1

where c1.fid=f.fid)

FNAME

------------------------------

Harshit

v). Find the names of faculty members who teach in every room in which some class is

taught. SQL> select f.fname from faculty f

where 5>(

select count(snum) from

enrolled e,class c

where e.cname=c.name

and c.fid=f.fid);

FNAME

------------------------------

Rajendra

Muddasir

Prashant

Gowri

Page 10: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 10

2. Flights Database

The following relations keep track of airline flight information: P.K. FLIGHTS (no: integer, from: string, to: string, distance: integer,Departs: time, arrives:

time, price: real)

P.K. AIRCRAFT (aid: integer, aname: string, cruisingrange: integer)

F.K. P.K. F.K. CERTIFIED (eid: integer, aid: integer)

P.K. 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.

SQL> create table flights(fno number,source varchar2(30),destination

varchar2(30),distance number,departs varchar2(10),arrives varchar2(10),

2 price number(10,2),constraint fl_pk_1 primary key(fno));

Table created.

SQL> create table aircraft(aid number,aname varchar2(20),cruising_range

number,constraint ac_pk_1 primary key(aid));

Table created.

SQL> create table employees(eid number,ename varchar2(30),salary number, constraint

em_pk_1 primary key(eid))

Table created.

SQL> create table certified(eid number,aid number,

constraint cr_pk_1 primary key(eid ,aid), constraint cr_fk_1 foreign key(eid) references

employees(eid), constraint cr_fk_2 foreign key(aid) references aircraft(aid))

Table created.

SQL> desc flights;

Name Null? Type

----------------------------------------- -------- ----------------------------

FNO NOT NULL NUMBER

SOURCE VARCHAR2(30)

DESTINATION VARCHAR2(30)

DISTANCE NUMBER

Page 11: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 11

DEPARTS VARCHAR2(10)

ARRIVES VARCHAR2(10)

PRICE NUMBER(10,2)

SQL>insert into flights(fno,source,destination,distance,departs,arrives,price)

values(&fno,&source,&destination,&distance,&departs,&arrives,&price)

SQL> /

Enter value for fno: 111

Enter value for source: 'Bangalore'

Enter value for destination: 'Delhi'

Enter value for distance: 1000

Enter value for departs: '11:30 pm'

Enter value for arrives: '01:30 pm'

Enter value for price: 8000

old 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(&fno,&source,&destination,&distance,&departs,&arrives,&price)

new 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(111,'Bangalore','Delhi',1000,'11:30 pm','01:30 pm',8000)

1 row created.

SQL> /

Enter value for fno: 112

Enter value for source: 'Mumbai'

Enter value for destination: 'Calcutta'

Enter value for distance: 1500

Enter value for departs: '11:30 pm'

Enter value for arrives: '02:00 pm'

Enter value for price: 10000

old 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(&fno,&source,&destination,&distance,&departs,&arrives,&price)

new 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(112,'Mumbai','Calcutta',1500,'11:30 pm','02:00 pm',10000)

1 row created.

SQL> /

Enter value for fno: 113

Enter value for source: 'Delhi'

Enter value for destination: 'Bangalore'

Enter value for distance: 1000

Enter value for departs: '05:00 am'

Enter value for arrives: '07:00 am'

Enter value for price: 7000

old 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(&fno,&source,&destination,&distance,&departs,&arrives,&price)

new 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(113,'Delhi','Bangalore',1000,'05:00 am','07:00 am',7000)

1 row created.

Page 12: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 12

SQL> /

Enter value for fno: 114

Enter value for source: 'Mysore'

Enter value for destination: 'Trivandrum'

Enter value for distance: 750

Enter value for departs: '7:15 am'

Enter value for arrives: '9:00 am'

Enter value for price: 8000

old 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(&fno,&source,&destination,&distance,&departs,&arrives,&price)

new 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(114,'Mysore','Trivandrum',750,'7:15 am','9:00 am',8000)

1 row created.

SQL> /

Enter value for fno: 115

Enter value for source: 'Chennai'

Enter value for destination: 'Hyderabad'

Enter value for distance: 600

Enter value for departs: '12:30 pm'

Enter value for arrives: '01:30 pm'

Enter value for price: 5000

old 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(&fno,&source,&destination,&distance,&departs,&arrives,&price)

new 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(115,'Chennai','Hyderabad',600,'12:30 pm','01:30 pm',5000)

1 row created.

SQL> /

Enter value for fno: 116

Enter value for source: 'Hyderabad'

Enter value for destination: 'Bangalore'

Enter value for distance: 600

Enter value for departs: '4:30 pm'

Enter value for arrives: '5:30 pm'

Enter value for price: 6000

old 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(&fno,&source,&destination,&distance,&departs,&arrives,&price)

new 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(116,'Hyderabad','Bangalore',600,'4:30 pm','5:30 pm',6000)

1 row created.

SQL> /

Enter value for fno: 117

Enter value for source: 'Bangalore'

Enter value for destination: 'Calcutta'

Enter value for distance: 1600

Enter value for departs: '12:00 am'

Page 13: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 13

Enter value for arrives: '02:00 am'

Enter value for price: 8000

old 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(&fno,&source,&destination,&distance,&departs,&arrives,&price)

new 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(117,'Bangalore','Calcutta',1600,'12:00 am','02:00 am',8000)

1 row created.

SQL> /

Enter value for fno: 118

Enter value for source: 'Trivandrum'

Enter value for destination: 'Mumbai'

Enter value for distance: 2000

Enter value for departs: '09:00 am'

Enter value for arrives: '12:00 am'

Enter value for price: 12000

old 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(&fno,&source,&destination,&distance,&departs,&arrives,&price)

new 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(118,'Trivandrum','Mumbai',2000,'09:00 am','12:00 am',12000)

1 row created.

SQL> /

Enter value for fno: 119

Enter value for source: 'Mumbai'

Enter value for destination: 'Delhi'

Enter value for distance: 1000

Enter value for departs: '3:15 pm'

Enter value for arrives: '5:00 pm'

Enter value for price: 7800

old 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(&fno,&source,&destination,&distance,&departs,&arrives,&price)

new 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(119,'Mumbai','Delhi',1000,'3:15 pm','5:00 pm',7800)

1 row created.

SQL> /

Enter value for fno: 120

Enter value for source: 'Bangalore'

Enter value for destination: 'Mumbai'

Enter value for distance: 1000

Enter value for departs: '1:00 pm'

Enter value for arrives: '2:00 pm'

Enter value for price: 5000

old 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(&fno,&source,&destination,&distance,&departs,&arrives,&price)

new 1: insert into flights(fno,source,destination,distance,departs,arrives,price)

values(120,'Bangalore','Mumbai',1000,'1:00 pm','2:00 pm',5000)

Page 14: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 14

1 row created.

SQL> /

Enter value for fno: 122

Enter value for source: 'Bangalore'

Enter value for destination: 'Delhi'

Enter value for distance: 1000

Enter value for departs: '2:30 pm'

Enter value for arrives: '4:30 pm'

Enter value for price: 7500

old 2:

VALUES(&FNO,&SOURCE,&DESTINATION,&DISTANCE,&DEPARTS,&ARRIVES,&PRICE)

new 2: VALUES(122,'Bangalore','Delhi',1000,'2:30 pm','4:30 pm',7500)

1 row created.

SQL> /

Enter value for fno: 123

Enter value for source: 'Bangalore'

Enter value for destination: 'Frankfurt'

Enter value for distance: 4500

Enter value for departs: '1:30 pm'

Enter value for arrives: '9:30 pm'

Enter value for price: 50000

old 2:

VALUES(&FNO,&SOURCE,&DESTINATION,&DISTANCE,&DEPARTS,&ARRIVES,&PRICE)

new 2: VALUES(123,'Bangalore','Frankfurt',4500,'1:30 pm','9:30 pm',50000)

1 row created.

SQL> /

Enter value for fno: 124

Enter value for source: 'Bangalore'

Enter value for destination: 'Frankfurt'

Enter value for distance: 4500

Enter value for departs: '2:30 am'

Enter value for arrives: '11:30 pm'

Enter value for price: 55000

old 2:

VALUES(&FNO,&SOURCE,&DESTINATION,&DISTANCE,&DEPARTS,&ARRIVES,&PRICE)

new 2: VALUES(124,'Bangalore','Frankfurt',4500,'2:30 am','11:30 pm',55000)

SQL> commit;

Commit complete.

Page 15: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 15

SQL> select * from flights;

FNO SOURCE DESTINATION DISTANCE DEPARTS ARRIVES PRICE ---------- ------------------------------ ------------------------------ ---------- ---------- ---------- ---------- 111 Bangalore Delhi 1000 11:30 pm 01:30 pm 8000 112 Mumbai Calcutta 1500 11:30 pm 02:00 pm 10000 113 Delhi Bangalore 1000 05:00 am 07:00 am 7000 114 Mysore Trivandrum 750 7:15 am 9:00 am 8000 115 Chennai Hyderabad 600 12:30 pm 01:30 pm 5000 116 Hyderabad Bangalore 600 4:30 pm 5:30 pm 6000 117 Bangalore Calcutta 1600 12:00 am 02:00 am 8000 118 Trivandrum Mumbai 2000 09:00 am 12:00 am 12000 119 Mumbai Delhi 1000 3:15 pm 5:00 pm 7800 120 Bangalore Mumbai 1000 1:00 pm 2:00 pm 5000 122 Bangalore Delhi 1000 2:30 pm 4:30 pm 7500 123 Bangalore Frankfurt 4500 1:30 pm 9:30 pm 50000 124 Bangalore Frankfurt 4500 2:30 am 11:30 pm 55000 13 rows selected.

SQL> insert into aircraft(aid,aname,cruising_range) values(&aid,&aname,&cruising_range)

SQL> /

Enter value for aid: 1001

Enter value for aname: 'Boein747'

Enter value for cruising_range: 1200

old 1: insert into aircraft(aid,aname,cruising_range) values(&aid,&aname,&cruising_range)

new 1: insert into aircraft(aid,aname,cruising_range) values(1001,'Boein747',1200)

1 row created.

SQL> /

Enter value for aid: 1002

Enter value for aname: 'Boeing777'

Enter value for cruising_range: 1500

old 1: insert into aircraft(aid,aname,cruising_range) values(&aid,&aname,&cruising_range)

new 1: insert into aircraft(aid,aname,cruising_range) values(1002,'Boeing777',1500)

1 row created.

SQL> /

Enter value for aid: 1003

Enter value for aname: 'Boeing787'

Enter value for cruising_range: 1200

old 1: insert into aircraft(aid,aname,cruising_range) values(&aid,&aname,&cruising_range)

new 1: insert into aircraft(aid,aname,cruising_range) values(1003,'Boeing787',1200)

1 row created.

SQL> /

Enter value for aid: 1004

Enter value for aname: 'Boeing898'

Enter value for cruising_range: 1300

old 1: insert into aircraft(aid,aname,cruising_range) values(&aid,&aname,&cruising_range)

new 1: insert into aircraft(aid,aname,cruising_range) values(1004,'Boeing898',1300)

Page 16: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 16

1 row created.

SQL> /

Enter value for aid: 1005

Enter value for aname: 'Boeing134'

Enter value for cruising_range: 1000

old 1: insert into aircraft(aid,aname,cruising_range) values(&aid,&aname,&cruising_range)

new 1: insert into aircraft(aid,aname,cruising_range) values(1005,'Boeing134',1000)

1 row created.

SQL> /

Enter value for aid: 1006

Enter value for aname: 'Airbus111'

Enter value for cruising_range: 1300

old 1: insert into aircraft(aid,aname,cruising_range) values(&aid,&aname,&cruising_range)

new 1: insert into aircraft(aid,aname,cruising_range) values(1006,'Airbus111',1300)

1 row created.

SQL> /

Enter value for aid: 1007

Enter value for aname: 'Airbus112'

Enter value for cruising_range: 1200

old 1: insert into aircraft(aid,aname,cruising_range) values(&aid,&aname,&cruising_range)

new 1: insert into aircraft(aid,aname,cruising_range) values(1007,'Airbus112',1200)

1 row created.

SQL> /

Enter value for aid: 1008

Enter value for aname: 'Airbus113'

Enter value for cruising_range: 1300

old 1: insert into aircraft(aid,aname,cruising_range) values(&aid,&aname,&cruising_range)

new 1: insert into aircraft(aid,aname,cruising_range) values(1008,'Airbus113',1300)

1 row created.

SQL> /

Enter value for aid: 1009

Enter value for aname: 'Airbus114'

Enter value for cruising_range: 1400

old 1: INSERT INTO AIRCRAFT(AID,ANAME,CRUISING_RANGE)

VALUES(&AID,&ANAME,&CRUISING_RANGE)

new 1: INSERT INTO AIRCRAFT(AID,ANAME,CRUISING_RANGE)

VALUES(1009,'Airbus114',1400)

1 row created.

SQL> /

Page 17: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 17

Enter value for aid: 1010

Enter value for aname: 'Airbus115'

Enter value for cruising_range: 1000

old 1: insert into aircraft(aid,aname,cruising_range) values(&aid,&aname,&cruising_range)

new 1: insert into aircraft(aid,aname,cruising_range) values(1010,'Airbus115',1000)

1 row created.

SQL> commit;

Commit complete.

SQL> select * from aircraft;

AID ANAME CRUISING_RANGE

---------- -------------------- ------------------------

1001 Boein747 1200

1002 Boeing777 1500

1003 Boeing787 1200

1004 Boeing898 1300

1005 Boeing134 1000

1006 Airbus111 1300

1007 Airbus112 1200

1008 Airbus113 1300

1009 Airbus114 1400

1010 Airbus115 1000

SQL> insert into employees(eid,ename,salary) values(&eid,&ename,&salary)

2 /

Enter value for eid: 1

Enter value for ename: 'Raju'

Enter value for salary: 50000

old 1: insert into employees(eid,ename,salary) values(&eid,&ename,&salary)

new 1: insert into employees(eid,ename,salary) values(1,'Raju',50000)

1 row created.

SQL> /

Enter value for eid: 2

Enter value for ename: 'Ravi'

Enter value for salary: 45000

old 1: insert into employees(eid,ename,salary) values(&eid,&ename,&salary)

new 1: insert into employees(eid,ename,salary) values(2,'Ravi',45000)

1 row created.

SQL> /

Enter value for eid: 3

Enter value for ename: 'Rakesh'

Page 18: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 18

Enter value for salary: 49000

old 1: insert into employees(eid,ename,salary) values(&eid,&ename,&salary)

new 1: insert into employees(eid,ename,salary) values(3,'Rakesh',49000)

1 row created.

SQL> /

Enter value for eid: 4

Enter value for ename: 'Suresh'

Enter value for salary: 80000

old 1: insert into employees(eid,ename,salary) values(&eid,&ename,&salary)

new 1: insert into employees(eid,ename,salary) values(4,'Suresh',80000)

1 row created.

SQL> /

Enter value for eid: 5

Enter value for ename: 'Lalith'

Enter value for salary: 75000

old 1: insert into employees(eid,ename,salary) values(&eid,&ename,&salary)

new 1: insert into employees(eid,ename,salary) values(5,'Lalith',75000)

1 row created.

SQL> /

Enter value for eid: 6

Enter value for ename: 'Gowri'

Enter value for salary: 60000

old 1: insert into employees(eid,ename,salary) values(&eid,&ename,&salary)

new 1: insert into employees(eid,ename,salary) values(6,'Gowri',60000)

1 row created.

SQL> /

Enter value for eid: 7

Enter value for ename: 'Shashank'

Enter value for salary: 55000

old 1: insert into employees(eid,ename,salary) values(&eid,&ename,&salary)

new 1: insert into employees(eid,ename,salary) values(7,'Shashank',55000)

1 row created.

SQL> /

Enter value for eid: 8

Enter value for ename: 'Vinay'

Enter value for salary: 49000

old 1: insert into employees(eid,ename,salary) values(&eid,&ename,&salary)

new 1: insert into employees(eid,ename,salary) values(8,'Vinay',49000)

1 row created.

SQL> /

Page 19: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 19

Enter value for eid: 9

Enter value for ename: 'Kumar'

Enter value for salary: 85000

old 1: insert into employees(eid,ename,salary) values(&eid,&ename,&salary)

new 1: insert into employees(eid,ename,salary) values(9,'Kumar',85000)

1 row created.

SQL> /

Enter value for eid: 10

Enter value for ename: 'Guru'

Enter value for salary: 65000

old 1: insert into employees(eid,ename,salary) values(&eid,&ename,&salary)

new 1: insert into employees(eid,ename,salary) values(10,'Guru',65000)

1 row created.

SQL> /

Enter value for eid: 11

Enter value for ename: 'Deva'

Enter value for salary: 7000

old 1: insert into employees(eid,ename,salary) values(&eid,&ename,&salary)

new 1: insert into employees(eid,ename,salary) values(11,'Deva',46000)

1 row created.

SQL> /

Enter value for eid: 12

Enter value for ename: 'Kiran'

Enter value for salary: 8000

old 1: insert into employees(eid,ename,salary) values(&eid,&ename,&salary)

new 1: insert into employees(eid,ename,salary) values(12,'Kiran',58000)

1 row created.

SQL> commit;

Commit complete.

SQL> select * from employees;

EID ENAME SALARY

---------- ------------------------------ ----------

1 Raju 50000

2 Ravi 45000

3 Rakesh 49000

4 Suresh 80000

5 Lalith 75000

Page 20: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 20

6 Gowri 60000

7 Shashank 55000

8 Vinay 49000

9 Kumar 85000

10 Guru 65000

11 Deva 46000

12 Kiran 58000

SQL> insert into certified(eid,aid) values(&eid,&aid)

2

SQL> /

Enter value for eid: 1

Enter value for aid: 1001

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(1,1001)

1 row created.

SQL> /

Enter value for eid: 1

Enter value for aid: 1002

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(1,1002)

1 row created.

SQL> /

Enter value for eid: 1

Enter value for aid: 1010

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(1,1010)

1 row created.

SQL> .

SQL> /

Enter value for eid: 2

Enter value for aid: 1006

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(2,1006)

1 row created.

SQL> /

Enter value for eid: 2

Enter value for aid: 1007

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(2,1007)

1 row created.

Page 21: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 21

SQL> /

Enter value for eid: 2

Enter value for aid: 1008

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(2,1008)

1 row created.

SQL> /

Enter value for eid: 3

Enter value for aid: 1003

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(3,1003)

1 row created.

SQL> /

Enter value for eid: 3

Enter value for aid: 1004

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(3,1004)

1 row created.

SQL> /

Enter value for eid: 3

Enter value for aid: 1005

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(3,1005)

1 row created.

SQL> /

Enter value for eid: 4

Enter value for aid: 1010

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(4,1010)

1 row created.

SQL> /

Enter value for eid: 4

Enter value for aid: 1009

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(4,1009)

1 row created.

SQL> /

Enter value for eid: 4

Enter value for aid: 1008

Page 22: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 22

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(4,1008)

1 row created.

SQL> /

Enter value for eid: 7

Enter value for aid: 1001

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(7,1001)

1 row created.

SQL> /

Enter value for eid: 7

Enter value for aid: 1002

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(7,1002)

1 row created.

SQL> /

Enter value for eid: 7

Enter value for aid: 1007

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(7,1007)

1 row created.

SQL> /

Enter value for eid: 10

Enter value for aid: 1003

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(10,1003)

1 row created.

SQL> /

Enter value for eid: 10

Enter value for aid: 1004

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(10,1004)

1 row created.

SQL> /

Enter value for eid: 10

Enter value for aid: 1005

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(10,1005)

Page 23: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 23

1 row created.

SQL> /

Enter value for eid: 10

Enter value for aid: 1007

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(10,1007)

1 row created.

SQL> /

Enter value for eid: 2

Enter value for aid: 1004

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(2,1004)

SQL> /

Enter value for eid: 12

Enter value for aid: 1001

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(12,1001)

1 row created.

SQL> /

Enter value for eid: 11

Enter value for aid: 1001

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(11,1001)

1 row created.

SQL> /

Enter value for eid: 11

Enter value for aid: 1003

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(11,1003)

1 row created.

SQL> /

Enter value for eid: 12

Enter value for aid: 1004

old 1: insert into certified(eid,aid) values(&eid,&aid)

new 1: insert into certified(eid,aid) values(12,1004)

1 row created.

SQL> commit;

Commit complete.

Page 24: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 24

SQL> select * from certified;

EID AID

---------- ----------

1 1001

1 1002

1 1010

2 1006

2 1007

2 1008

3 1003

3 1004

3 1005

4 1010

4 1009

4 1008

7 1001

7 1002

7 1007

10 1003

10 1004

10 1005

10 1007

2 1004

12 1001

11 1001

11 1003

12 1004

i). Find the names of aircraft such that all pilots certified to operate them have salaries

more than Rs.80, 000.

SQL> select a.aname from

2 aircraft a,certified c,employees e

3 where a.aid=c.aid

4 and c.eid=e.eid

5 and e.salary>80000

ANAME

--------------------

Boein747

Boeing777

Airbus115

Boeing787

Boeing898

Boeing134

Airbus112

ii). For each pilot who is certified for more than three aircrafts,find the eid and the

maximum cruisingrange of the aircraft for which she or he is certified.

Page 25: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 25

SQL> select c.eid,max(a.cruising_range) from certified c,aircraft a

2 where c.aid=a.aid

3 group by c.eid

4 having count(c.eid)>3

EID MAX(A.CRUISING_RANGE)

---------- ---------------------

2 1300

10 1300

iii). Find the names of pilots whose salary is less than the price of the cheapest route

from Bengaluru to Frankfurt.

SQL> select distinct e.ename from employees e ,certified c

2 where e.eid=c.eid

3 and e.salary <(select min(price) from flights where source='Bangalore' and

destination='Frankfurt')

ENAME

------------------------------

Deva

Rakesh

Ravi

iv). 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.aname,avg(e.salary) from aircraft a,employees e ,certified c

2 where a.aid=c.aid

3 and c.eid=e.eid

4 and a.cruising_range>1000

5 group by a.aname

ANAME AVG(E.SALARY)

-------------------- -------------

Airbus111 45000

Airbus112 60666.6667

Airbus113 62500

Airbus114 80000

Boein747 62250

Boeing777 72500

Boeing787 59000

Boeing898 58500

v). Find the names of pilots certified for some Boeing aircraft.

Page 26: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 26

SQL> select distinct e.ename from employees e, certified c,aircraft a

2 where e.eid=c.eid

3 and c.aid=a.aid

4 and a.aname like 'boe%'

ENAME

------------------------------

Deva

Guru

Kiran

Raju

Rakesh

Ravi

Shashank

vi). Find the aids of all aircraft that can be used on routes from Bengaluru to New Delhi.

SQL> select aid from aircraft where cruising_range>(select distinct distance from flights

where source='Bangalore' and destination='Delhi')

AID

----------

1001

1002

1003

1004

1006

1007

1008

1009

Page 27: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 27

3. Student Enroll and Book Adaption database

Consider the following database of Student Enrollment in courses and books adopted for

each course. P.K. STUDENT (Reg-no: String, Name: String, Major: String, Bdate: date)

P.K.

COURSE (Course-no: Int, Cname: String, Dept: String)

F.K. F.K.

ENROLL (Reg-no: String, Course-no: Int, Sem: Int, Marks: Int)

P.K.

TEXT (Book-isbn: Int, Book-title: String, Publisher: String, Author: String)

F.K. Not Null F.K.

BOOK_ADOPTION (Course-no: Int, Sem: Int, Book-isbn: Int)

i). Create the above tables by properly specifying the primary keys and the foreign

keys.

SQL> create table student

2 (reg_no char(10) primary key,

3 name varchar2(20),

4 major varchar2(6),

5 bdate date);

Table created.

SQL> create table course

2 (course_no number(6) primary key,

3 cname varchar2(20),

4 dept varchar2(20));

Table created.

SQL> create table enroll

2 (reg_no char(6) references student(reg_no),

3 course_no number(6) references course(course_no),

4 sem number(2),

5 marks number(5,2));

Table created.

SQL> create table text

2 (book_isbn number(10) primary key,

3 book_title varchar2(20),

4 publisher varchar2(20),

5 author varchar2(20));

Page 28: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 28

Table created.

SQL> create table book_adoption

2 (course_no number(6) references course(course_no),

3 sem number(2) not null,

4 book_isbn number(10) references text(book_isbn));

Table created.

ii). Enter atleast five tuples for each relation.

SQL> insert into student values ('&reg_no', '&name', '&major', '&bdate');

SQL> select * from student;

REG_NO NAME MAJOR BDATE

------------- -------------- ------------ ------------

MCA01 Anand Male 12-MAY-80

MCA02 Afsar Male 12-JUN-82

MCA03 Charles Male 02-OCT-81

MCA04 Jaqlin Female 18-MAY-83

MBA05 Smith Male 08-JUN-82

MBA06 Rojas Male 11-DEC-82

SQL> insert into course values (&course_no, '&cname', '&dept');

SQL> select * from course;

COURSE_NO CNAME DEPT

-------------- --------------- -------------

001 MBA PG

002 MCA PG

003 ECE BE

004 CS BE

005 ELE BE

006 ME BE

SQL> insert into enroll values ('&reg_no', &course_no, &sem, &marks);

SQL> select * from enroll;

REG_NO COURSE_NO SEM MARKS

------------- --------------- ---------- ------------

MCA01 002 3 72

MCA02 002 4 80

MCA03 002 6 77

MCA04 002 3 60

MBA05 001 3 68

MBA06 001 3 65

Page 29: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 29

SQL> insert into text values (&book_isbn, '&book_title', '&publisher', '&author');

SQL> select * from text;

BOOK_ISBN BOOK_TITLE PUBLISHER AUTHOR

-------------- ----------------- ---------------- -----------------

1001 Let Us C BPB Kanetkar

1002 C++ Primer EEE Linnman

1003 Power Ele EEE Sen

1004 Electricals I Tata Theraja

1005 DBMS Tata Navathe

1006 ADA BPB Stallman

SQL> insert into book_adoption values (&course_no, &sem, &book_isbn);

SQL> select * from book_adoption;

COURSE_NO SEM BOOK_ISBN

--------------- ----- --------------

001 3 1005

001 3 1003

002 4 1002

002 3 1006

002 6 1001

005 3 1004

iii). Demonstrate how you add a new text book to the database & make this book be

adopted by some department.

SQL> insert into text values (1007, ‘JAVA’, ‘Tata’, ‘Patricton’);

SQL> insert into book_adoption values (002, 4, 1007);

SQL> select * from text;

BOOK_ISBN BOOK_TITLE PUBLISHER AUTHOR

-------------- ----------------- ---------------- -----------------

1001 Let Us C BPB Kanetkar

1002 C++ Primer EEE Linnman

1003 Power Ele EEE Sen

1004 Electricals I Tata Theraja

1005 DBMS Tata Navathe

1006 ADA BPB Stallman

1007 JAVA Tata Patricton

Page 30: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 30

SQL> select * from book_adoption;

COURSE_NO SEM BOOK_ISBN

--------------- ----- --------------

001 3 1005

001 3 1003

002 4 1002

002 3 1006

002 6 1001

005 3 1004

002 4 1007

iv). Produce a list of text books (include Course_no, Book_ISBN, Book_Title) in the

alphabetical order for courses offered by the ‘PG’ dept that use more than two

books.

SQL> select b.course_no, t.book_isbn, t.book_title

2 from text t, book_adoption b, course c

3 where t.book_isbn=b.book_isbn and

4 b.course_no=c.course_no and

5 c.dept=’pg’ and b.course_no in

6 (select course_no

7 from book_adoption

8 group by course_no

9 having count(*)>2)

10 order by t.book_title;

COURSE_NO BOOK_ISBN BOOK_TITLE

-------------- -------------- ---------------

002 1002 C++ Primer

002 1006 ADA

002 1001 Let Us C

002 1007 JAVA

v). List any department that has all its adopted books published by a specific publisher.

SQL> select distinct (dept)

2 from course where course_no in

3 (select course_no

4 from book_adoption where book_isbn in

5 (select book_isbn

7 from text where publisher='bpb'));

DEPT

------------

PG

Page 31: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 31

4. Book Dealer Database

The following tables are maintained by a Book Dealer. P.K.

AUTHOR (Author-id: Int, Name: String, City: String, Country: String)

P.K.

PUBLISHER (Publisher-id: Int, Name: String, City: String, Country: String)

P.K.

CATEGORY (Category-id: Int, Description: String)

P.K. F.K. F.K.

CATALOG (Book-id: Int, Title: String, Author-id: Int, Publisher-id: Int, F.K.

Category-id: Int, Year: Int, Price: Int)

P.K. F.K.

ORDER-DETAILS (Order-no: Int, Book-id: Int, Qty: Int)

i). Create the above tables by properly specifying the primary keys and the foreign

keys.

SQL> create table author

2 (author_id number(6) primary key,

3 name varchar2(20),

4 city varchar2(20),

5 country varchar2(20));

Table created.

SQL> create table publisher

2 (publisher_id number(6) primary key,

3 name varchar2(30),

4 city varchar2(20),

5 country varchar2(20));

Table created.

SQL> create table category

2 (category_id number(6) primary key,

3 description varchar2(20));

Table created.

SQL> create table catalog

2 (book_id number(6) primary key,

3 title varchar2(20),

4 author_id number(6) references author,

5 publisher_id number(6) references publisher,

6 category_id number(6) references category,

7 year number(4),

8 price number(7,2));

Page 32: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 32

Table created.

SQL> create table order_details

2 (order_no number(6) primary key,

3 book_id number(6) references catalog,

4 qty number(6));

Table created.

ii). Enter atleast five tuples for each relation.

SQL> insert into author values (&author_id, '&name', '&city', '&country');

SQL> select * from author;

AUTHOR_ID NAME CITY COUNTRY

------------- ------------------- ------------------ --------------------

001 Kanetkar Mumbai India

002 Balaguruswami Chennai India

003 Sharma Delhi India

004 Gosling New York USA

005 Lippman New York USA

006 Gupta Mumbai India

SQL> insert into publisher values (&publisher_id, '&name', '&city', '&country');

SQL> select * from publisher;

PUBLISHER_ID NAME CITY COUNTRY

---------------- ------------------------- -------------------- ---------------------

101 BPB Mumbai India

102 EEE Durban South Africa

103 Khanna Delhi India

104 TMH Delhi India

105 O’Reilly New York USA

SQL> insert into category values (&category_id, '&description');

SQL> select * from category;

CATEGORY_ID DESCRIPTION

---------------- --------------------

201 Computer

202 Accounts

203 Programming

204 Electronics

205 Electrical

SQL> insert into catalog values(&book_id, '&title', &author_id, &publisher_id,

2 &category_id,&year,&price);

Page 33: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 33

SQL> select * from catalog;

BOOK_ID TITLE AUTHOR_ID PUBLISHER_ID CATEGORY_ID YEAR PRICE

---------- ---------------- ------------- ---------------- ---------------- ------ ------

1001 Let Us C 001 101 203 2002 150

1002 JAVA2 004 105 203 2004 340

1003 Accounts 003 103 202 2000 180

1004 J2EE 004 102 201 2005 400

1005 C++ Primer 005 102 203 2002 300

1006 C++ 002 104 203 2000 200

SQL> insert into order_details values (&order_no, &book_id, &qty);

SQL> select * from order_details;

ORDER_NO BOOK_ID QTY

------------- ---------- -----------

5001 1001 100

5002 1002 200

5003 1004 150

5004 1003 100

5005 1002 100

5006 1001 100

iii). Give the details of the Authors who have two 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

and the year of publication is after 2000.

SQL> select distinct(author_id), name, city, country

2 from author where author_id in

3 (select author_id from catalog

4 where price>(select avg(price) from catalog)

5 and year>2000

6 group by author_id

7 having count(*)>=2);

AUTHOR_ID NAME CITY COUNTRY

------------- -------------------- -------------------- --------------------

004 Gosling New York USA

iv). Find the author of the book which has the maximum sales.

SQL> create view sales_details as(

select od.book_id as book_no,c.price as cost,

sum(od.qty) as quantity,

sum(od.qty*c.price)as sales

from order_details od,catalog c,author a

where od.book_id=c.book_id and

a.author_id=c.author_id

group by od.book_id,c.price);

Page 34: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 34

view created

SQL> select a.author_id,a.name,s.book_no,s.sales

from author a,catalog c,sales_details s

where a.author_id=c.author_id and

s.book_no=c.book_id and

s.sales=(select max(sales) from sales_details);

A.AUTHOR_ID A.NAME S.BOOK_NO S.SALES

------------- -------------------- -------------------- --------------------

004 Gosling 1002 102000

v). Demonstrate how you increase the price of books published by a specific publisher

by 10%.

SQL> update catalog

2 set price= (price * 1.1)

3 where publisher_id in

4 (select publisher_id from publisher

5 where name=’eee’);

2 rows updated.

SQL> select * from catalog;

BOOK_ID TITLE AUTHOR_ID PUBLISHER_ID CATEGORY_ID YEAR PRICE

---------- ---------------- ------------- ---------------- ---------------- ------ ------

1001 Let Us C 001 101 203 2002 150

1002 JAVA2 004 105 203 2004 340

1003 Accounts 003 103 202 2000 180

1004 J2EE 004 102 201 2005 440

1005 C++ Primer 005 102 203 2002 330

1006 C++ 002 104 203 2000 200

Page 35: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 35

5. Banking Database

Consider the following database for a Banking Enterprise. P. K.

BRANCH (Br-name: String, Br-city: String, Assets: Real)

P.K. F.K.

ACCOUNT (Acc-no: Int, Br-name: String, Bal: Real)

F.K. F.K.

DEPOSITOR (Cust-name: String, Acc-no: Int)

P.K.

CUSTOMER (Cust-name: String, Cust-street: String, City: String)

P.K. F.K.

LOAN (Loan-no: Int, Br-name: String, amt: Real)

F.K. F.K. BORROWER (Cust-name: String, Loan-no: Int)

i). Create the above tables by properly specifying the primary keys and the foreign

keys.

SQL> create table branch

2 (br_name varchar2(20) primary key,

3 br_city varchar2(20),

4 assets number(10,2));

Table created.

SQL> create table account

2 (acc_no number(10) primary key,

3 br_name varchar2(20) references branch,

4 bal number(10,2));

Table created.

SQL> create table customer

2 (cust_name varchar2(20) primary key,

3 cust_street varchar2(20),

4 cust_city varchar2(20));

Table created.

SQL> create table depositor

2 (cust_name varchar2(20) references customer on delete cascade,

3 acc_no number(10) references account on delete cascade);

Table created.

Page 36: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 36

SQL> create table loan

2 (loan_no number(10) primary key,

3 br_name varchar2(20) references branch on delete cascade,

4 amt number(10,2));

Table created.

SQL> create table borrower

2 (cust_name varchar2(20) references customer on delete cascade,

3 loan_no number(10) references loan on delete cascade);

Table created.

ii). Enter atleast five tuples for each relation.

SQL> insert into branch values ('&br_name', '&br_city', &assets);

SQL> select * from branch;

BR_NAME BR_CITY ASSETS

-------------------- -------------------- ---------

HAL Bangalore 800000

Main Bangalore 1000000

Varthur Bangalore 700000

M G Road New Delhi 800000

High Road Hyderabad 1200000

SQL> insert into account values (&acc_no, '&br_name', &bal);

SQL> select * from account;

ACC_NO BR_NAME BAL

---------- -------------------- ---------

011001 HAL 50000

011002 HAL 12000

011003 Varthur 80000

011004 Main 10000

011005 Main 12000

011006 High Road 80000

SQL> insert into customer values ('&cust_name', '&cust_street', '&cust_city');

SQL> select * from customer;

CUST_NAME CUST_STREET CUST_CITY

-------------------- ----------------------- --------------------

Smith Ulsoor Bangalore

Charles MG Road Bangalore

Rojas PO Road Chennai

Manju BEML Road Bangalore

John HAL Bangalore

Page 37: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 37

SQL> insert into depositor values ('&cust_name', &acc_no);

SQL> select * from depositor;

CUST_NAME ACC_NO

-------------------- ---------

Smith 011001

Smith 011003

Manju 011002

Manju 011006

Smith 011004

Smith 011005

SQL> insert into loan values (&loan_no, '&br_name', &amt);

SQL> select * from loan;

LOAN_NO BR_NAME AMT

----------- ------------------- ---------

1001 M G Road 10000

1002 High Road 50000

1003 HAL 20000

1004 Main 5000

1005 Main 80000

1006 Varthur 10000

SQL> insert into borrower values ('&cust_name', &loan_no);

SQL> select * from borrower;

CUST_NAME LOAN_NO

-------------------- -----------

Manju 1001

Smith 1004

Smith 1005

Charles 1003

Rojas 1002

iii). Find all customers who have atleast 2 accounts at the Main branch.

SQL> select distinct (d.cust_name)

2 from depositor d, account a

3 where d.acc_no = a.acc_no and br_name = ‘Main’

4 group by d.cust_name having count(d.acc_no)>=2;

CUST_NAME

--------------------

Smith

Page 38: Dbms Lab Manual 10csl57

Dept of IS&E VVCE

DBMS Laboratory (10CSL57) 38

iv). Find all the customers who have an account at all the branches located in a specific

city.

SQL> select distinct(d1. cust_name)

2 from depositor d1 where not exists

3 ((select br_name from branch where br_city=’Bangalore’)

4 minus

5 (select a.br_name from depositor d,account a

6 where d.acc_no=a.acc_no and d1.cust_name=d.cust_name));

CUST_NAME

--------------------

Smith

v). Demonstrate how to delete all account tuples at every branch located in a specific

city.

SQL> delete account

2 where br_name in

3 (select br_name

4 from branch

5 where br_city='Bangalore');

5 rows deleted.

SQL> select * from account;

ACC_NO BR_NAME BAL

---------- -------------------- ---------

011006 High Road 80000

SQL> select * from depositor;

CUST_NAME ACC_NO

-------------------- ---------

Manju 011006