You are on page 1of 38

Dept of IS&E

VVCE

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

DBMS Laboratory (10CSL57)

Dept of IS&E

VVCE

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

DBMS Laboratory (10CSL57)

Dept of IS&E

VVCE

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

DBMS Laboratory (10CSL57)

Dept of IS&E
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

VVCE

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;

DBMS Laboratory (10CSL57)

Dept of IS&E
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

VVCE

DBMS Laboratory (10CSL57)

Dept of IS&E
SQL> desc class; Name Null? Type ----------------------------------------- -------- ---------------------------NAME NOT NULL VARCHAR2(10) MEETS_AT VARCHAR2(10) ROOM VARCHAR2(10) FID NUMBER

VVCE

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 ---------1SEM 2SEM 3SEM 4SEM 5SEM 6SEM 7SEM 8SEM MEETS_AT ROOM FID ---------- ---------- ---------8:30 R11 11 9:30 R12 22 9:30 R13 33 10:30 R12 11 8:30 R12 44 11:30 R13 55 12:30 R13 11 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');

DBMS Laboratory (10CSL57)

Dept of IS&E
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

VVCE

DBMS Laboratory (10CSL57)

Dept of IS&E

VVCE

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

DBMS Laboratory (10CSL57)

Dept of IS&E
SNAME -----------------------------Raju Ali Carter Sudhir Ilyaz

VVCE

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

DBMS Laboratory (10CSL57)

Dept of IS&E

VVCE

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

DBMS Laboratory (10CSL57)

10

Dept of IS&E
DEPARTS ARRIVES PRICE VARCHAR2(10) VARCHAR2(10) NUMBER(10,2)

VVCE

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.

DBMS Laboratory (10CSL57)

11

Dept of IS&E

VVCE

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 Enter value Enter value Enter value Enter value for for for for for fno: 117 source: 'Bangalore' destination: 'Calcutta' distance: 1600 departs: '12:00 am'

DBMS Laboratory (10CSL57)

12

Dept of IS&E

VVCE

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)

DBMS Laboratory (10CSL57)

13

Dept of IS&E

VVCE

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.

DBMS Laboratory (10CSL57)

14

Dept of IS&E
SQL> select * from flights;
FNO SOURCE DESTINATION DISTANCE DEPARTS ARRIVES

VVCE

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)

DBMS Laboratory (10CSL57)

15

Dept of IS&E

VVCE

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> /

DBMS Laboratory (10CSL57)

16

Dept of IS&E

VVCE

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'

DBMS Laboratory (10CSL57)

17

Dept of IS&E
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> /

VVCE

DBMS Laboratory (10CSL57)

18

Dept of IS&E
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

VVCE

---------- ------------------------------ ---------1 Raju 50000 2 Ravi 45000 3 Rakesh 49000 4 Suresh 80000 5 Lalith 75000

DBMS Laboratory (10CSL57)

19

Dept of IS&E
6 7 8 9 10 11 12 Gowri Shashank Vinay Kumar Guru Deva Kiran 60000 55000 49000 85000 65000 46000 58000

VVCE

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.

DBMS Laboratory (10CSL57)

20

Dept of IS&E
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

VVCE

DBMS Laboratory (10CSL57)

21

Dept of IS&E
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)

VVCE

DBMS Laboratory (10CSL57)

22

Dept of IS&E
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.

VVCE

DBMS Laboratory (10CSL57)

23

Dept of IS&E
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

VVCE

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.

DBMS Laboratory (10CSL57)

24

Dept of IS&E
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 10 1300 1300

VVCE

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.

DBMS Laboratory (10CSL57)

25

Dept of IS&E
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

VVCE

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

DBMS Laboratory (10CSL57)

26

Dept of IS&E

VVCE

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).
SQL> 2 3 4 5

Create the above tables by properly specifying the primary keys and the foreign keys.
create table student (reg_no char(10) primary key, name varchar2(20), major varchar2(6), bdate date);

Table created. SQL> 2 3 4 create table course (course_no number(6) primary key, cname varchar2(20), dept varchar2(20));

Table created. SQL> 2 3 4 5 create table enroll (reg_no char(6) references student(reg_no), course_no number(6) references course(course_no), sem number(2), marks number(5,2));

Table created. SQL> 2 3 4 5 create table text (book_isbn number(10) primary key, book_title varchar2(20), publisher varchar2(20), author varchar2(20));

DBMS Laboratory (10CSL57)

27

Dept of IS&E

VVCE

Table created. SQL> 2 3 4 create table book_adoption (course_no number(6) references course(course_no), sem number(2) not null, 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 ------------- -------------MCA01 Anand MCA02 Afsar MCA03 Charles MCA04 Jaqlin MBA05 Smith MBA06 Rojas MAJOR -----------Male Male Male Female Male Male BDATE -----------12-MAY-80 12-JUN-82 02-OCT-81 18-MAY-83 08-JUN-82 11-DEC-82

SQL> insert into course values (&course_no, '&cname', '&dept'); SQL> select * from course; COURSE_NO -------------001 002 003 004 005 006 CNAME --------------MBA MCA ECE CS ELE ME DEPT ------------PG PG BE BE BE 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

DBMS Laboratory (10CSL57)

28

Dept of IS&E

VVCE

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

BOOK_ISBN -------------1001 1002 1003 1004 1005 1006

BOOK_TITLE ----------------Let Us C C++ Primer Power Ele Electricals I DBMS ADA

PUBLISHER AUTHOR ---------------- ----------------BPB Kanetkar EEE Linnman EEE Sen Tata Theraja Tata Navathe 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 -------------1001 1002 1003 1004 1005 1006 1007 BOOK_TITLE ----------------Let Us C C++ Primer Power Ele Electricals I DBMS ADA JAVA PUBLISHER AUTHOR ---------------- ----------------BPB Kanetkar EEE Linnman EEE Sen Tata Theraja Tata Navathe BPB Stallman Tata Patricton

DBMS Laboratory (10CSL57)

29

Dept of IS&E
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

VVCE

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.
select b.course_no, t.book_isbn, t.book_title from text t, book_adoption b, course c where t.book_isbn=b.book_isbn and b.course_no=c.course_no and c.dept=pg and b.course_no in (select course_no from book_adoption group by course_no having count(*)>2) order by t.book_title;

SQL> 2 3 4 5 6 7 8 9 10

COURSE_NO BOOK_ISBN BOOK_TITLE -------------- -------------- --------------002 1002 C++ Primer 002 1006 ADA 002 1001 Let Us C 002 1007 JAVA

v).
SQL> 2 3 4 5 7

List any department that has all its adopted books published by a specific publisher.
select distinct (dept) from course where course_no in (select course_no from book_adoption where book_isbn in (select book_isbn from text where publisher='bpb'));

DEPT -----------PG

DBMS Laboratory (10CSL57)

30

Dept of IS&E

VVCE

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

CATALOG (Book-id: Int, Title: String, Author-id: Int, Publisher-id: Int, 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> 2 3 4 5 6 7 8 create table catalog (book_id number(6) primary key, title varchar2(20), author_id number(6) references author, publisher_id number(6) references publisher, category_id number(6) references category, year number(4), price number(7,2));

DBMS Laboratory (10CSL57)

31

Dept of IS&E
Table created. SQL> 2 3 4 create table order_details (order_no number(6) primary key, book_id number(6) references catalog, qty number(6));

VVCE

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 ------------- ------------------001 Kanetkar 002 Balaguruswami 003 Sharma 004 Gosling 005 Lippman 006 Gupta CITY COUNTRY ------------------ -------------------Mumbai India Chennai India Delhi India New York USA New York USA Mumbai India

SQL> insert into publisher values (&publisher_id, '&name', '&city', '&country'); SQL> select * from publisher; PUBLISHER_ID NAME ---------------- ------------------------101 BPB 102 EEE 103 Khanna 104 TMH 105 OReilly CITY COUNTRY -------------------- --------------------Mumbai India Durban South Africa Delhi India Delhi India New York USA

SQL> insert into category values (&category_id, '&description'); SQL> select * from category; CATEGORY_ID ---------------201 202 203 204 205 DESCRIPTION -------------------Computer Accounts Programming Electronics Electrical

SQL> insert into catalog values(&book_id, '&title', &author_id, &publisher_id, 2 &category_id,&year,&price);

DBMS Laboratory (10CSL57)

32

Dept of IS&E
SQL> select * from catalog;

VVCE

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.
select distinct(author_id), name, city, country from author where author_id in (select author_id from catalog where price>(select avg(price) from catalog) and year>2000 group by author_id having count(*)>=2);

SQL> 2 3 4 5 6 7

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

DBMS Laboratory (10CSL57)

33

Dept of IS&E
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

VVCE

v).
SQL> 2 3 4 5

Demonstrate how you increase the price of books published by a specific publisher by 10%.
update catalog set price= (price * 1.1) where publisher_id in (select publisher_id from publisher 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

DBMS Laboratory (10CSL57)

34

Dept of IS&E

VVCE

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).
SQL> 2 3 4

Create the above tables by properly specifying the primary keys and the foreign keys.
create table branch (br_name varchar2(20) primary key, br_city varchar2(20), assets number(10,2));

Table created. SQL> 2 3 4 create table account (acc_no number(10) primary key, br_name varchar2(20) references branch, bal number(10,2));

Table created. SQL> 2 3 4 create table customer (cust_name varchar2(20) primary key, cust_street varchar2(20), 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.

DBMS Laboratory (10CSL57)

35

Dept of IS&E
SQL> 2 3 4 create table loan (loan_no number(10) primary key, br_name varchar2(20) references branch on delete cascade, amt number(10,2));

VVCE

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 -------------------HAL Main Varthur M G Road High Road BR_CITY -------------------Bangalore Bangalore Bangalore New Delhi Hyderabad ASSETS --------800000 1000000 700000 800000 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 -------------------Smith Charles Rojas Manju John CUST_STREET ----------------------Ulsoor MG Road PO Road BEML Road HAL CUST_CITY -------------------Bangalore Bangalore Chennai Bangalore Bangalore

DBMS Laboratory (10CSL57)

36

Dept of IS&E

VVCE

SQL> insert into depositor values ('&cust_name', &acc_no); SQL> select * from depositor; CUST_NAME -------------------Smith Smith Manju Manju Smith Smith ACC_NO --------011001 011003 011002 011006 011004 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).
SQL> 2 3 4

Find all customers who have atleast 2 accounts at the Main branch.
select distinct (d.cust_name) from depositor d, account a where d.acc_no = a.acc_no and br_name = Main group by d.cust_name having count(d.acc_no)>=2;

CUST_NAME -------------------Smith

DBMS Laboratory (10CSL57)

37

Dept of IS&E

VVCE

iv).
SQL> 2 3 4 5 6

Find all the customers who have an account at all the branches located in a specific city.
select distinct(d1. cust_name) from depositor d1 where not exists ((select br_name from branch where br_city=Bangalore) minus (select a.br_name from depositor d,account a 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

DBMS Laboratory (10CSL57)

38