Вы находитесь на странице: 1из 49

Lab Manual: DBMS Lab

PROGRAM 1: INSURANCE DATABASE I. Consider the Insurance database given below. underlined and the data types are specified. The primary keys are

PERSON (driver id #: String, name: String, address: String) CAR (Regno: String, model: String, year: int) ACCIDENT (report-number: int, date: date, location: String) OWNS (driver-id #: String, Regno: String) PARTICIPATED (driver-id: String, Regno: String, report-number: int, damageamount: int) i) ii) iii) Create the above tables by properly specifying the primary keys and the foreign keys. Enter at least five tuples for each relation. Demonstrate how you a. Update the damage amount for the car with a specific Regno in the accident with report number 12 to 25000. b. Add a new accident to the database. Find the total number of people who owned cars that involved in accidents in 2008. Find the number of accidents in which cars belonging to a specific model were involved. Generate suitable reports. Create suitable front end for querying and displaying the results. PERSON driverid Name Address

iv) v) vi) vii)

CAR regno Model Year

ACCIDENT Report-number Date Location

OWNS Driverid Regno

PARTICIPATED Driverid Report-number Regno Damageamt

Lab Manual: DBMS Lab


QUERY 1: Create the above tables by properly specifying the primary keys and the foreign keys. SQL> create table person(driverid varchar(10),name varchar(20), address varchar(30),primary key(driverid)); Table created. SQL> desc person Name Null? ------------------------------- -------DRIVERID NOT NULL NAME ADDRESS Type ---VARCHAR2(10) VARCHAR2(20) VARCHAR2(30)

SQL> create table car(regno varchar(10),model varchar(10),year int,primary key(regno)); Table created. SQL> desc car Name Null? ------------------------------- -------REGNO NOT NULL MODEL YEAR Type ---VARCHAR2(10) VARCHAR2(10) NUMBER(38)

SQL> create table accident(reportno int,adate date,location varchar(20),primary key(reportno)); Table created. SQL> desc accident Name Null? ------------------------------- -------REPORTNO NOT NULL ADATE LOCATION Type ---NUMBER(38) DATE VARCHAR2(20)

SQL> create table owns(driverid varchar(10),regno varchar(10), primary key(driverid,regno),foreign key(driverid) references person(driverid),foreign key(regno) references car(regno)); Table created. SQL> desc owns Name ------------------------------DRIVERID REGNO Null? -------NOT NULL NOT NULL Type ---VARCHAR2(10) VARCHAR2(10)

SQL>create table participated(driverid varchar(10), regno varchar(10),reportno int, damageamt int, primary key(driverid,regno,reportno), foreign key(driverid) references person(driverid), foreign key(regno) references car(regno), foreign key(reportno) references accident(reportno)); Table created. SQL> desc participated

Lab Manual: DBMS Lab


Name ------------------------------DRIVERID REGNO REPORTNO DAMAGEAMT Null? -------NOT NULL NOT NULL NOT NULL Type ---VARCHAR2(10) VARCHAR2(10) NUMBER(38) NUMBER(38)

QUERY 2: Enter at least five tuples for each relation SQL> insert into person values('&driverid','&name','&address'); Enter value for driverid: A01 Enter value for name: Richard Enter value for address: Srinivas Nagar old 1: insert into person values('&driverid','&name','&address') new 1: insert into person values('A01','Richard','Srinivas Nagar') 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> commit; Commit complete. SQL> select * from person; driverid: A05 name: John address: Hanumanth Nagar into person values('&driverid','&name','&address') into person values('A05','John','Hanumanth Nagar') driverid: A04 name: Venu address: N.R.Colony into person values('&driverid','&name','&address') into person values('A04','Venu','N.R.Colony') driverid: A03 name: Smith address: Ashoknagar into person values('&driverid','&name','&address') into person values('A03','Smith','Ashoknagar') driverid: A02 name: Pradeep address: Rajajinagar into person values('&driverid','&name','&address') into person values('A02','Pradeep','Rajajinagar')

Lab Manual: DBMS Lab


DRIVERID ---------A01 A02 A03 A04 A05 NAME -------------------Richard Pradeep Smith Venu John ADDRESS -----------------------------Srinivas Nagar Rajajinagar Ashoknagar N.R.Colony Hanumanth Nagar

SQL> insert into car values('&regno','&model',&year); Enter value for regno: KA052250 Enter value for model: Indica Enter value for year: 1990 old 1: insert into car values('&regno','&model',&year) new 1: insert into car values('KA052250','Indica',1990) 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> commit; Commit complete. regno: KA041702 model: Audi year: 2005 into car values('&regno','&model',&year) into car values('KA041702','Audi',2005) regno: KA053408 model: Honda year: 2008 into car values('&regno','&model',&year) into car values('KA053408','Honda',2008) regno: KA095477 model: Toyota year: 1998 into car values('&regno','&model',&year) into car values('KA095477','Toyota',1998) regno: KA031181 model: Lancer year: 1957 into car values('&regno','&model',&year) into car values('KA031181','Lancer',1957)

Lab Manual: DBMS Lab


SQL> select * from car; REGNO MODEL YEAR ---------- ---------- ---------KA052250 Indica 1990 KA031181 Lancer 1957 KA095477 Toyota 1998 KA053408 Honda 2008 KA041702 Audi 2005 SQL> insert into accident values(&reportno,'&adate','&location'); Enter value for reportno: 11 Enter value for adate: 01-JAN-03 Enter value for location: Mysore Road old 1: insert into accident values(&reportno,'&adate','&location') new 1: insert into accident values(111,'01-JAN-03','Mysore Road') 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> commit; Commit complete. SQL> select * from accident; reportno: 15 adate: 04-MAR-05 location: Kanakpura Road into accident values(&reportno,'&adate','&location') into accident values(115,'04-MAR-05','Kanakpura Road') reportno: 13 adate: 21-JAN-03 location: Bulltemple Road into accident values(&reportno,'&adate','&location') into accident values(113,'21-JAN-03','Bulltemple Road') reportno: 12 adate: 02-FEB-04 location: Southend Circle into accident values(&reportno,'&adate','&location') into accident values(112,'02-FEB-04','Southend Circle')

reportno: 14 adate: 17-FEB-08 location: Mysore Road into accident values(&reportno,'&adate','&location') into accident values(114,'17-FEB-08','Mysore Road')

Lab Manual: DBMS Lab

REPORTNO ---------11 12 13 14 15

ADATE --------01-JAN-03 02-FEB-04 21-JAN-03 17-FEB-08 04-MAR-05

LOCATION -------------------Mysore Road Southend Circle Bulltemple Road Mysore Road Kanakpura Road

SQL> insert into owns values('&driverid','&regno'); Enter value for driverid: A01 Enter value for regno: KA052250 old 1: insert into owns values('&driverid','&regno') new 1: insert into owns values('A01','KA052250') 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> commit; Commit complete. SQL> select * from owns; DRIVERID REGNO ---------- ---------A01 KA052250 A02 KA053408 A04 KA031181 A03 KA095477 A05 KA041702 SQL> insert into participated values('&driverid','&regno',&reportno,&damt); driverid: A02 regno: KA053408 into owns values('&driverid','&regno') into owns values('A02','KA053408')

driverid: A04 regno: KA031181 into owns values('&driverid','&regno') into owns values('A04','KA031181')

driverid: A03 regno: KA095477 into owns values('&driverid','&regno') into owns values('A03','KA095477')

driverid: A05 regno: KA041702 into owns values('&driverid','&regno') into owns values('A05','KA041702')

Lab Manual: DBMS Lab


Enter Enter Enter Enter old new value for value for value for value for 1: insert 1: insert driverid: A01 regno: KA052250 reportno: 11 damt: 10000 into participated values('&driverid','&regno',&reportno,&damt) into participated values('A01','KA052250',11,10000)

1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> commit; Commit complete. SQL> select * from participated; DRIVERID ---------A01 A02 REGNO REPORTNO DAMAGEAMT ---------- ---------- ---------KA052250 11 10000 KA053408 12 50000 driverid: A05 regno: KA041702 reportno: 15 damt: 5000 into participated values('&driverid','&regno',&reportno,&damt) into participated values('A05','KA041702',15,5000) driverid: A04 regno: KA031181 reportno: 14 damt: 3000 into participated values('&driverid','&regno',&reportno,&damt) into participated values('A04','KA031181',14,3000) driverid: A03 regno: KA095477 reportno: 13 damt: 25000 into participated values('&driverid','&regno',&reportno,&damt) into participated values('A03','KA095477',13,25000) driverid: A02 regno: KA053408 reportno: 12 damt: 50000 into participated values('&driverid','&regno',&reportno,&damt) into participated values('A02','KA053408',12,50000)

Lab Manual: DBMS Lab


A03 A04 A05 KA095477 KA031181 KA041702 13 14 15 25000 3000 5000

QUERY 3: a) Update the damage amount for the car with a specific Regno in the accident with report number 12 to 25000. SQL> update participated set damageamt=25000 where regno='KA053408' and reportno=12; 1 row updated. SQL> commit; Commit complete. SQL> select * from participated; DRIVERID ---------A01 A02 A03 A04 A05 b) REGNO REPORTNO DAMAGEAMT ---------- ---------- ---------KA052250 11 10000 KA053408 12 25000 KA095477 13 25000 KA031181 14 3000 KA041702 15 5000

Add a new accident to the database.

SQL> insert into accident values(16,'15-MAR-08','Domlur'); 1 row created. SQL> select * from accident; REPORTNO ---------11 12 13 14 15 16 ADATE --------01-JAN-03 02-FEB-04 21-JAN-03 17-FEB-08 04-MAR-05 15-MAR-08 LOCATION -------------------Mysore Road Southend Circle Bulltemple Road Mysore Road Kanakpura Road Domlur

6 rows selected.

QUERY 4: Find the total number of people who owned cars that were involved in accidents in 2008. SQL> select count(distinct driverid) CNT from participated a, accident b where a.reportno=b.reportno and b.adate like '%08';

Lab Manual: DBMS Lab


CNT ---------1 QUERY 5: Find the number of accidents in which cars belonging to a specific model were involved. SQL> select count(reportno) CNT from car c,participated p where c.regno=p.regno and model='Lancer'; CNT ---------1

PROGRAM 2: ORDER PROCESSING DATABASE II. Consider the following application in a company. relations for an Order Processing database

CUSTOMER (CUST #: int, cname: String, city: String)

Lab Manual: DBMS Lab


ORDER (order #: int, odate: date, cust #: int, ord-Amt: int) ITEM (item #: int, unit-price: int) ORDER-ITEM (order #: int, item #: int, qty: int) WAREHOUSE (warehouse #: int, city: String) SHIPMENT (order #: int, warehouse #: int, ship-date: date) i) Create the above tables by properly specifying the primary keys and the foreign keys and the foreign keys. ii) Enter at least five tuples for each relation. iii) Produce a listing: CUSTNAME, #oforders, AVG_ORDER_AMT, where the middle column is the total numbers of orders by the customer and the last column is the average order amount for that customer. iv) List the order# for orders that were shipped from all warehouses that the company has in a specific city. v) Demonstrate how you delete item# 10 from the ITEM table and make that field null in the ORDER_ITEM table. vi) Generate suitable reports. vii) Create suitable front end for querying and displaying the results. CUSTOMER Cust-no Cname City

ORDER Order-no Odate Cust-no Order-amount

ITEM Item-no ORDER-ITEM Order-no Item-no Qty Price

WAREHOUSE Warehouse-no City

SHIPMENT Order-no Warehouse-no Date QUERY 1: Create the above tables by properly specifying the primary keys and the foreign keys. SQL> create table customer(custno int,cname varchar(20),city varchar(20), 2 primary key(custno)); Table created.

10

Lab Manual: DBMS Lab

SQL> desc customer Name Null? ------------------------------- -------CUSTNO NOT NULL CNAME CITY

Type ---NUMBER(38) VARCHAR2(20) VARCHAR2(20)

SQL> create table order(orderno int,odate date,custno int,ordamt int, 2 primary key(orderno),foreign key(custno) references customer(custno)); Table created. SQL> desc order Name Null? ------------------------------- -------ORDERNO NOT NULL ODATE CUSTNO ORDAMT Type ---NUMBER(38) DATE NUMBER(38) NUMBER(38)

SQL> create table item(itemno int,unitprice int,primary key(itemno)); Table created. SQL> desc item Name Null? ------------------------------- -------ITEMNO NOT NULL UNITPRICE Type ---NUMBER(38) NUMBER(38)

SQL> create table order_item(orderno int,itemno int,qty int, 2 primary key(orderno), foreign key(orderno) references order (orderno), 3 foreign key(itemno) references item (itemno) on delete set NULL); Table created. SQL> desc order_item Name ------------------------------ORDERNO ITEMNO QTY Null? -------NOT NULL NOT NULL Type ---NUMBER(38) NUMBER(38) NUMBER(38)

SQL> create table warehouse(warehouseno int,city varchar(20), 2 primary key(warehouseno)); Table created. SQL> desc warehouse Name Null? ------------------------------- -------WAREHOUSENO NOT NULL CITY Type ---NUMBER(38) VARCHAR2(20)

SQL> create table shipment(orderno int,warehouseno int,shipdate date, 2 primary key(orderno,warehouseno), 3 foreign key(orderno) references order(orderno), 4 foreign key(warehouseno) references warehouse(warehouseno)); Table created.

11

Lab Manual: DBMS Lab


SQL> desc shipment Name ------------------------------ORDERNO WAREHOUSENO SHIPDATE

Null? -------NOT NULL NOT NULL

Type ---NUMBER(38) NUMBER(38) DATE

QUERY 2: Enter at least five tuples for each relation SQL> insert into customer values(&custno,'&cname','&city'); Enter value for custno: 771 Enter value for cname: PUSHPA K Enter value for city: BANGALORE old 1: insert into customer values(&custno,'&cname','&city') new 1: insert into customer values(771,'PUSHPA K','BANGALORE') 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. custno: 772 cname: SUMAN city: MUMBAI into customer values(&custno,'&cname','&city') into customer values(772,'SUMAN','MUMBAI')

custno: 773 cname: SOURAV city: CALICUT into customer values(&custno,'&cname','&city') into customer values(773,'SOURAV','CALICUT')

custno: 774 cname: LAILA city: HYDERABAD into customer values(&custno,'&cname','&city') into customer values(774,'LAILA','HYDERABAD')

custno: 775 cname: FAIZAL city: BANGALORE into customer values(&custno,'&cname','&city') into customer values(775,'FAIZAL','BANGALORE')

SQL> commit; Commit complete. SQL> select * from customer; CUSTNO ---------771 772 CNAME -------------------PUSHPA K SUMAN CITY -------------------BANGALORE MUMBAI

12

Lab Manual: DBMS Lab


773 SOURAV 774 LAILA 775 FAIZAL CALICUT HYDERABAD BANGALORE

SQL> insert into order values(&ordid,'&odate',&custno,&ordamt); Enter value for ordid: 111 Enter value for odate: 22-JAN-02 Enter value for custno: 771 Enter value for ordamt: 18000 old 1: insert into order values(&ordid,'&odate',&custno,&ordamt) new 1: insert into order values(111,'22-JAN-02',771,18000) 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert ordid: 112 odate: 30-JUL-02 custno: 774 ordamt: 6000 into order values(&ordid,'&odate',&custno,&ordamt) into order values(112,'30-JUL-02',774,6000)

ordid: 113 odate: 03-APR-03 custno: 775 ordamt: 9000 into order values(&ordid,'&odate',&custno,&ordamt) into order values(113,'03-APR-03',775,9000)

ordid: 114 odate: 03-NOV-03 custno: 775 ordamt: 29000 into order values(&ordid,'&odate',&custno,&ordamt) into order values(114,'03-NOV-03',775,29000)

ordid: 115 odate: 10-DEC-03 custno: 773 ordamt: 29000. into order values(&ordid,'&odate',&custno,&ordamt) into order values(115,'10-DEC-03',773,29000.)

ordid: 116 odate: 19-AUG-04 custno: 772 ordamt: 56000 into order values(&ordid,'&odate',&custno,&ordamt)

13

Lab Manual: DBMS Lab


new 1: insert into order values(116,'19-AUG-04',772,56000)

1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> commit; Commit complete. ordid: 120 odate: 13-OCT-05 custno: 775 ordamt: 29000 into order values(&ordid,'&odate',&custno,&ordamt) into order values(120,'13-OCT-05',775,29000) ordid: 119 odate: 13-FEB-05 custno: 774 ordamt: 29000 into order values(&ordid,'&odate',&custno,&ordamt) into order values(119,'13-FEB-05',775,29000) ordid: 118 odate: 20-NOV-04 custno: 775 ordamt: 29000 into order values(&ordid,'&odate',&custno,&ordamt) into order values(118,'20-NOV-04',775,29000) ordid: 117 odate: 10-SEP-04 custno: 771 ordamt: 20000 into order values(&ordid,'&odate',&custno,&ordamt) into order values(117,'10-SEP-04',771,20000)

SQL> select * from order; ORDERNO ---------111 112 ODATE CUSTNO ORDAMT --------- ---------- ---------22-JAN-02 771 18000 30-JUL-02 774 6000

14

Lab Manual: DBMS Lab


113 114 115 116 117 118 119 120 03-APR-03 03-NOV-03 10-DEC-03 19-AUG-04 10-SEP-04 20-NOV-04 13-FEB-05 13-OCT-05 775 775 773 772 771 775 774 775 9000 29000 29000 56000 20000 29000 29000 29000

10 rows selected. SQL> insert into item values(&itemno,&unitprice); Enter value for itemno: 5001 Enter value for unitprice: 503 old 1: insert into item values(&itemno,&unitprice) new 1: insert into item values(5001,503) 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> commit; Commit complete. SQL> select * from item; ITEMNO UNITPRICE ---------- ---------5001 503 5002 750 itemno: 5002 unitprice: 750 into item values(&itemno,&unitprice) into item values(5002,750)

itemno: 5003 unitprice: 150 into item values(&itemno,&unitprice) into item values(5003,150)

itemno: 5004 unitprice: 600 into item values(&itemno,&unitprice) into item values(5004,600)

itemno: 5005 unitprice: 890 into item values(&itemno,&unitprice) into item values(5005,890)

15

Lab Manual: DBMS Lab


5003 5004 5005 150 600 890

SQL> insert into order_item values(&orderno,&itemno,&qty); Enter value for orderno: 111 Enter value for itemno: 5001 Enter value for qty: 50 old 1: insert into order_item values(&orderno,&itemno,&qty) new 1: insert into order_item values(111,5001,50) 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert orderno: 112 itemno: 5003 qty: 20 into order_item values(&orderno,&itemno,&qty) into order_item values(112,5003,20)

orderno: 113 itemno: 5002 qty: 50 into order_item values(&orderno,&itemno,&qty) into order_item values(113,5002,50)

orderno: 114 itemno: 5005 qty: 60 into order_item values(&orderno,&itemno,&qty) into order_item values(114,5005,60)

orderno: 115 itemno: 5004 qty: 90 into order_item values(&orderno,&itemno,&qty) into order_item values(115,5004,90)

orderno: 116 itemno: 5001 qty: 10 into order_item values(&orderno,&itemno,&qty) into order_item values(116,5001,10) orderno: 117 itemno: 5003 qty: 80 into order_item values(&orderno,&itemno,&qty) into order_item values(117,5003,80)

16

Lab Manual: DBMS Lab


1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> commit; Commit complete. SQL> select * from order_item; ORDERNO ITEMNO QTY ---------- ---------- ---------111 5001 50 112 5003 20 113 5002 50 114 5005 60 115 5004 90 116 5001 10 117 5003 80 118 5005 50 119 5002 10 120 5004 45 10 rows selected. SQL> insert into warehouse values(&warehouseno,'&city'); Enter value for warehouseno: 1 Enter value for city: DELHI old 1: insert into warehouse values(&warehouseno,'&city') new 1: insert into warehouse values(1,'DELHI') 1 row created. SQL> / Enter value for warehouseno: 2 Enter value for city: BOMBAY old 1: insert into warehouse values(&warehouseno,'&city') new 1: insert into warehouse values(2,'BOMBAY') 1 row created. orderno: 118 itemno: 5005 qty: 50 into order_item values(&orderno,&itemno,&qty) into order_item values(118,5005,50)

orderno: 119 itemno: 5002 qty: 10 into order_item values(&orderno,&itemno,&qty) into order_item values(119,5002,10)

orderno: 120 itemno: 5004 qty: 45 into order_item values(&orderno,&itemno,&qty) into order_item values(120,5004,45)

17

Lab Manual: DBMS Lab

SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created.

warehouseno: 3 city: CHENNAI into warehouse values(&warehouseno,'&city') into warehouse values(3,'CHENNAI')

warehouseno: 4 city: BANGALORE into warehouse values(&warehouseno,'&city') into warehouse values(4,'BANGALORE')

warehouseno: 5 city: BANGALORE into warehouse values(&warehouseno,'&city') into warehouse values(5,'BANGALORE')

warehouseno: 6 city: DELHI into warehouse values(&warehouseno,'&city') into warehouse values(6,'DELHI')

warehouseno: 7 city: BOMBAY into warehouse values(&warehouseno,'&city') into warehouse values(7,'BOMBAY')

warehouseno: 8 city: CHENNAI into warehouse values(&warehouseno,'&city') into warehouse values(8,'CHENNAI')

warehouseno: 9 city: DELHI into warehouse values(&warehouseno,'&city') into warehouse values(9,'DELHI')

warehouseno: 10 city: BANGALORE into warehouse values(&warehouseno,'&city') into warehouse values(10,'BANGALORE')

18

Lab Manual: DBMS Lab

SQL> commit; Commit complete. SQL> select * from warehouse; WAREHOUSENO CITY ----------- -------------------1 DELHI 2 BOMBAY 3 CHENNAI 4 BANGALORE 5 BANGALORE 6 DELHI 7 BOMBAY 8 CHENNAI 9 DELHI 10 BANGALORE 10 rows selected. SQL> insert into shipment values(&orderno,&warehouseno,'&shipdate'); Enter value for orderno: 111 Enter value for warehouseno: 1 Enter value for shipdate: 10-FEB-02 old 1: insert into shipment values(&orderno,&warehouseno,'&shipdate') new 1: insert into shipment values(111,1,'10-FEB-02') 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert orderno: 112 warehouseno: 5 shipdate: 10-SEP-02 into shipment values(&orderno,&warehouseno,'&shipdate') into shipment values(112,5,'10-SEP-02')

orderno: 113 warehouseno: 8 shipdate: 10-FEB-03 into shipment values(&orderno,&warehouseno,'&shipdate') into shipment values(113,8,'10-FEB-03')

orderno: 114 warehouseno: 3 shipdate: 10-DEC-03 into shipment values(&orderno,&warehouseno,'&shipdate') into shipment values(114,3,'10-DEC-03') orderno: 115 warehouseno: 9 shipdate: 19-JAN-04 into shipment values(&orderno,&warehouseno,'&shipdate') into shipment values(115,9,'19-JAN-04')

19

Lab Manual: DBMS Lab

1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> commit; Commit complete. SQL> select * from shipment; ORDERNO WAREHOUSENO SHIPDATE ---------- ----------- --------111 1 10-FEB-02 112 5 10-SEP-02 orderno: 120 warehouseno: 6 shipdate: 21-DEC-05 into shipment values(&orderno,&warehouseno,'&shipdate') into shipment values(120,6,'21-DEC-05') orderno: 119 warehouseno: 7 shipdate: 30-APR-05 into shipment values(&orderno,&warehouseno,'&shipdate') into shipment values(119,7,'30-APR-05') orderno: 118 warehouseno: 7 shipdate: 30-NOV-04 into shipment values(&orderno,&warehouseno,'&shipdate') into shipment values(118,7,'30-NOV-04') orderno: 117 warehouseno: 5 shipdate: 10-SEP-04 into shipment values(&orderno,&warehouseno,'&shipdate') into shipment values(117,5,'10-SEP-04') orderno: 116 warehouseno: 1 shipdate: 20-SEP-04 into shipment values(&orderno,&warehouseno,'&shipdate') into shipment values(116,1,'20-SEP-04')

20

Lab Manual: DBMS Lab


113 114 115 116 117 118 119 120 10 rows selected. QUERY 3: Produce a listing: CUSTNAME, #of orders, AVG_ORDER_AMT, where the middle column is the total numbers of orders by the customer and the last column is the average order amount for that customer. SQL> select cname CUSTNAME,count(orderno) NOOFORDERS,avg(ordamt) AVGORDAMT 2 from customer a,order b 3 where a.custno=b.custno group by cname; CUSTNAME NOOFORDERS AVGORDAMT -------------------- ---------- ---------FAIZAL 4 24000 LAILA 2 17500 PUSHPA K 2 19000 SOURAV 1 29000 SUMAN 1 56000 QUERY 4: List the order# for orders that were shipped from all warehouses that the company has in a specific city. SQL> select * from order_cust where orderno in( 2 select orderno from shipment where warehouseno in( 3 select warehouseno from warehouse where city='CHENNAI')); ORDERNO ---------113 114 ODATE CUSTNO ORDAMT --------- ---------- ---------03-APR-03 775 9000 03-NOV-03 775 29000 8 3 9 1 5 7 7 6 10-FEB-03 10-DEC-03 19-JAN-04 20-SEP-04 10-SEP-04 30-NOV-04 30-APR-05 21-DEC-05

QUERY 5: Demonstrate how you delete item # 10 from ITEM table and make null in the ORDER_ITEM table. SQL> delete from item1 where itemno=5001; 1 row deleted.

PROGRAM 3: STUDENT ENROLLMENT DATABASE III. Consider the following database of student enrollment in courses and books adopted for each course. STUDENT (regno: String, name: String, major: String, bdate: date)

21

Lab Manual: DBMS Lab


COURSE (course #: int, cname: String, dept: String) ENROLL (regno: String, cname: String, sem: int, marks: int) BOOK_ADOPTION (course #: int, sem: int, book-ISBN: int) TEXT(book-ISBN:int, book-title:String, publisher:String, author:String) i) Create the above tables by properly specifying the primary keys and the foreign keys. ii) Enter at least five tuples for each relation. iii) Demonstrate how you add a new text book to the database and make this book be adopted by some department. iv) Produce a list of text books (include Course #, Book-ISBN, Booktitle) in the alphabetical order for courses offered by the CS department that use more than two books. v) List any department that has all its adopted books published by a specific publisher. vi) Create suitable front end for querying and displaying the results. STUDENT Regno Name Major Bdate

COURSE Course_no Cname Dept

ENROLL Regno Course_no Marks Sem

BOOK-ADOPTION Course_no Sem Bookisbn

TEXT Bookisbn Booktitle Publisher Author

QUERY 1: Create the above tables by properly specifying the primary keys and the foreign keys. SQL> create table student(regno varchar(10),name varchar(20), 2 major varchar(15),bdate date,primary key(regno));

22

Lab Manual: DBMS Lab


Table created. SQL> desc student Name Null? ------------------------------- -------REGNO NOT NULL NAME MAJOR BDATE Type ---VARCHAR2(10) VARCHAR2(20) VARCHAR2(15) DATE

SQL> create table course(courseno int,cname varchar(10),dept varchar(10), 2 primary key(courseno)); Table created. SQL> desc course Name Null? ------------------------------- -------COURSENO NOT NULL CNAME DEPT SQL> 2 3 4 Type ---NUMBER(38) VARCHAR2(10) VARCHAR2(10)

create table enroll(regno varchar(10),courseno int,sem int,marks int primary key(regno,courseno), foreign key(regno) references student(regno), foreign key(courseno) references course(courseno));

Table created. SQL> desc enroll Name ------------------------------REGNO COURSENO SEM MARKS Null? -------NOT NULL NOT NULL Type ---VARCHAR2(10) NUMBER(38) NUMBER(38) NUMBER(38)

SQL> create table text(book_isbn int,book_title varchar(50), 2 publisher varchar(25),author varchar(25), primary key(book_isbn)); Table created. SQL> desc text Name Null? ------------------------------- -------BOOK_ISBN NOT NULL BOOK_TITLE PUBLISHER AUTHOR Type ---NUMBER(38) VARCHAR2(50) VARCHAR2(25) VARCHAR2(25)

SQL> create table book_adoption(courseno int,sem int,book_isbn int, 2 foreign key(courseno) references course(courseno), 3 foreign key(book_isbn) references text(book_isbn)); Table created. SQL> desc book_adoption

23

Lab Manual: DBMS Lab


Name Null? ------------------------------- -------COURSENO SEM BOOK_ISBN Type ---NUMBER(38) NUMBER(38) NUMBER(38)

QUERY 2: Enter at least five tuples for each relation SQL> insert into student values('&regno','&name','&major','&bdate'); Enter value for regno: CS01 Enter value for name: RAM Enter value for major: DS Enter value for bdate: 12-MAR-86 old 1: insert into student values('&regno','&name','&major','&bdate') new 1: insert into student values('CS01','RAM','DS','12-MAR-86') 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. regno: IS02 name: SMITH major: USP bdate: 23-DEC-87 into student values('&regno','&name','&major','&bdate') into student values('IS02','SMITH','USP','23-DEC-87')

regno: EC03 name: AHMED major: SNS bdate: 17-APR-85 into student values('&regno','&name','&major','&bdate') into student values('EC03','AHMED','SNS','17-APR-85')

regno: CS03 name: SNEHA major: DBMS bdate: 01-JAN-87 into student values('&regno','&name','&major','&bdate') into student values('CS03','SNEHA','DBMS','01-JAN-87')

SQL> / Enter value for regno: TC05 Enter value for name: AKHILA Enter value for major: EC Enter value for bdate: 06-OCT-86 old 1: insert into student values('&regno','&name','&major','&bdate') new 1: insert into student values('TC05','AKHILA','EC','06-OCT-86') 1 row created. SQL> commit; Commit complete. SQL> select * from student; REGNO NAME MAJOR BDATE

24

Lab Manual: DBMS Lab


---------CS01 IS02 EC03 CS03 TC05 -------------------RAM SMITH AHMED SNEHA AKHILA --------------DS USP SNS DBMS EC --------12-MAR-86 23-DEC-87 17-APR-85 01-JAN-87 06-OCT-86

SQL> insert into course values(&courseno,'&cname','&dept'); Enter value for courseno: 11 Enter value for cname: DS Enter value for dept: CS old 1: insert into course values(&courseno,'&cname','&dept') new 1: insert into course values(11,'DS','CS') 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> commit; Commit complete. SQL> select * from course; COURSENO ---------11 22 CNAME ---------DS USP DEPT ---------CS IS courseno: 22 cname: USP dept: IS into course values(&courseno,'&cname','&dept') into course values(22,'USP','IS')

courseno: 33 cname: SNS dept: EC into course values(&courseno,'&cname','&dept') into course values(33,'SNS','EC')

courseno: 44 cname: DBMS dept: CS into course values(&courseno,'&cname','&dept') into course values(44,'DBMS','CS')

courseno: 55 cname: EC dept: TC into course values(&courseno,'&cname','&dept') into course values(55,'EC','TC')

25

Lab Manual: DBMS Lab


33 SNS 44 DBMS 55 EC EC CS TC

SQL> insert into enroll values('&regno',&courseno,&sem,&marks); Enter value for regno: CS01 Enter value for courseno: 11 Enter value for sem: 85 Enter value for marks: 4 old 1: insert into enroll values('&regno',&courseno,&sem,&marks) new 1: insert into enroll values('CS01',11,4,85) 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. regno: IS02 courseno: 22 sem: 80 marks: 6 into enroll values('&regno',&courseno,&sem,&marks) into enroll values('IS02',22,6,80)

regno: EC03 courseno: 33 sem: 80 marks: 2 into enroll values('&regno',&courseno,&sem,&marks) into enroll values('EC03',33,2,80)

regno: CS03 courseno: 44 sem: 75 marks: 6 into enroll values('&regno',&courseno,&sem,&marks) into enroll values('CS03',44,6,75)

regno: TC05 courseno: 55 sem: 87 marks: 2 into enroll values('&regno',&courseno,&sem,&marks) into enroll values('TC05',55,2,87)

SQL> commit; Commit complete. SQL> select * from enroll; REGNO COURSENO SEM MARKS ---------- ---------- ---------- ---------CS01 11 4 85 IS02 22 6 80

26

Lab Manual: DBMS Lab


EC03 CS03 TC05 33 44 55 2 6 2 80 75 87

SQL> insert into text values(&book_isbn,'&book_title','&publish','&author'); Enter value for book_isbn: 1 Enter value for book_title: DS and C Enter value for publish: Princeton Enter value for author: Padma Reddy old 1: insert into text values(&book_isbn,'&book_title','&publish','&author') new 1: insert into text values(1,'DS and C','Princeton','Padma Reddy') 1 row created. SQL> / Enter value for book_isbn: 2 Enter value for book_title: Fundamentals of DS Enter value for publish: Princeton Enter value for author: Godse old 1: insert into text values(&book_isbn,'&book_title','&publish','&author') new 1: insert into text values(2,'Fundamentals of DS','Princeton','Godse') 1 row created. SQL> / Enter value for book_isbn: 3 Enter value for book_title: Fundamentals of DBMS Enter value for publish: Princeton Enter value for author: Navathe old 1: insert into text values(&book_isbn,'&book_title','&publish','&author') new1: insert into text values(3,'Fundamentals of DBMS','Princeton','Navathe') 1 row created. SQL> / Enter value for book_isbn: 4 Enter value for book_title: SQL Enter value for publish: Princeton Enter value for author: Foley old 1: insert into text values(&book_isbn,'&book_title','&publish','&author') new 1: insert into text values(4,'SQL','Princeton','Foley') 1 row created. SQL> / Enter value for book_isbn: 5 Enter value for book_title: Electronic circuits Enter value for publish: TMH Enter value for author: Elmasri old 1: insert into text values(&book_isbn,'&book_title','&publish','&author') new 1: insert into text values(5,'Electronic circuits','TMH','Elmasri') 1 row created. SQL> / Enter value for book_isbn: 5 Enter value for book_title: Electronic circuits Enter value for publish: TMH Enter value for author: Elmasri old 1: insert into text values(&book_isbn,'&book_title','&publish','&author')

27

Lab Manual: DBMS Lab


new 1: insert into text values(5,'Electronic circuits','TMH','Elmasri')

1 row created. SQL> / Enter value for book_isbn: 6 Enter value for book_title: Adv unix prog Enter value for publish: TMH Enter value for author: Stevens old 1: insert into text values(&book_isbn,'&book_title','&publish','&author') new 1: insert into text values(6,'Adv unix prog','TMH','Stevens') 1 row created. SQL> commit; Commit complete. SQL> select * from text; BOOK_ISBN --------1 2 3 4 5 6 BOOK_TITLE ---------------------DS and C Fundamentals of DS Fundamentals of DBMS SQL Electronic circuits Adv unix prog PUBLISHER ------------------------Princeton Princeton Princeton Princeton TMH TMH AUTHOR ----------------Padma Reddy Godse Navathe Foley Elmasri Stevens

6 rows selected. SQL> insert into book_adoption values(&courseno,&sem,&book_isbn); Enter value for courseno: 11 Enter value for sem: 4 Enter value for book_isbn: 1 old 1: insert into book_adoption values(&courseno,&sem,&book_isbn) new 1: insert into book_adoption values(11,4,1) 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. courseno: 11 sem: 4 book_isbn: 2 into book_adoption values(&courseno,&sem,&book_isbn) into book_adoption values(11,4,2)

SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert

courseno: 44 sem: 6 book_isbn: 3 into book_adoption values(&courseno,&sem,&book_isbn) into book_adoption values(44,6,3)

28

Lab Manual: DBMS Lab

1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> commit; Commit complete.

courseno: 44 sem: 6 book_isbn: 4 into book_adoption values(&courseno,&sem,&book_isbn) into book_adoption values(44,6,4)

courseno: 55 sem: 2 book_isbn: 5 into book_adoption values(&courseno,&sem,&book_isbn) into book_adoption values(55,2,5)

courseno: 22 sem: 6 book_isbn: 6 into book_adoption values(&courseno,&sem,&book_isbn) into book_adoption values(22,6,6)

SQL> select * from book_adoption; COURSENO SEM BOOK_ISBN ---------- ---------- ---------11 4 1 11 4 2 44 6 3 44 6 4 55 2 5 22 6 6 6 rows selected.

QUERY 3: Demonstrate how you add a new text book to the database and make this book be adopted by some department. SQL> insert into text values(7,'DBMS Intro','Pearson','Godse'); 1 row created.

29

Lab Manual: DBMS Lab


SQL> commit; Commit complete. SQL> select * from text; BOOK_ISBN BOOK_TITLE --------- ---------------------1 DS and C 2 Fundamentals of DS 3 Fundamentals of DBMS 4 SQL 5 Electronic circuits 6 Adv unix prog 7 DBMS Intro PUBLISHER ------------------------Princeton Princeton Princeton Princeton TMH TMH Pearson AUTHOR ----------------Padma Reddy Godse Navathe Foley Elmasri Stevens Godse

SQL> insert into book_adoption values(55,2,7); 1 row created. SQL> commit; Commit complete. SQL> select * from book_adoption; COURSENO SEM BOOK_ISBN ---------- ---------- ---------11 4 1 11 4 2 44 6 3 44 6 4 55 2 5 22 6 6 55 2 7 7 rows selected. QUERY 4: Produce a list of text books (include Course #, Book-ISBN, Booktitle) in the alphabetical order fir courses offered by CS department that use more than two books. SQL> select c.courseno Courseno,t.book_title BookTitle,t.book_isbn BookISBN 2 from course c,book_adoption b,text t 3 where c.dept='CS' and c.courseno=b.courseno and 4 t.book_isbn=b.book_isbn and 5 c.courseno in(select courseno from book_adoption group by courseno 6 having count(*)>1) 7 order by t.book_title; COURSENO BOOKTITLE BOOKISBN ---------- -------------------------------------------------- ---------11 DS and C 1 44 Fundamentals of DBMS 3 11 Fundamentals of DS 2 44 SQL 4 QUERY 5: List any department that has all its adopted books published by a specific publisher. SQL> select c.dept DEPT,t.publisher PUBLISHER 2 from text t,book_adoption b,course c

30

Lab Manual: DBMS Lab


3 4 where b.book_isbn=t.book_isbn and c.courseno=b.courseno and t.publisher='Princeton'; PUBLISHER ------------------------Princeton Princeton Princeton Princeton

DEPT ---------CS CS CS CS

PROGRAM 4: BOOK DEALER DATABASE IV. The following tables are maintained by a book dealer: AUTHOR(author-id: int, name: String, city: String, country: String)

31

Lab Manual: DBMS Lab


PUBLISHER(publisher-id: int, name: String, city: String, country: String) CATALOG(book-id: int, title: String, author-id: int, publisher-id: int, category-id: int, year: int, price: int) CATEGORY(category-id: int, description: String) ORDER-DETAILS(order-no: int, book-id: int, quantity: int) i) Create the above tables by properly specifying the primary keys and the foreign keys. ii) Enter at least five tuples for each relation. iii) Give the details of the authors who have 2 or more books in the catalog and the price of the books in the catalog and the year of publication is after 2000. iv) Find the author of the book which has maximum sales. v) Demonstrate how you increase the price of books published by a specific publisher by 10%. vi) Generate suitable reports. vii) Create suitable front end for querying and displaying the results. AUTHOR Authorid Name City Country

PUBLISHER publisherid Name City Country

CATALOG Book-id Title Authored Publisherid Category-id Year Price

CATEGORY Category-id Description

ORDER-DETAILS Order-no Book-id Quantity

QUERY 1: Create the above tables by properly specifying the primary keys and the foreign keys. SQL> create table author(authorid int,name varchar(20),city varchar(20),

32

Lab Manual: DBMS Lab


2 country varchar(15),primary key(authorid)); Table created. SQL> desc author; Name Null? ------------------------------- -------AUTHORID NOT NULL NAME CITY COUNTRY Type ---NUMBER(38) VARCHAR2(20) VARCHAR2(20) VARCHAR2(15)

SQL> create table publisher(publisherid int,name varchar(20), 2 city varchar(20),country varchar(15), 3 primary key(publisherid)); Table created. SQL> desc publisher; Name Null? ------------------------------- -------PUBLISHERID NOT NULL NAME CITY COUNTRY Type ---NUMBER(38) VARCHAR2(20) VARCHAR2(20) VARCHAR2(15)

SQL> create table category(categoryid int,description varchar(20), 2 primary key(categoryid)); Table created. SQL> desc category; Name Null? ------------------------------- -------CATEGORYID NOT NULL DESCRIPTION Type ---NUMBER(38) VARCHAR2(20)

SQL> create table catalog(bookid int,title varchar(20),authorid int, 2 publisherid int,categoryid int,year int,price int, 3 primary key(bookid), 4 foreign key(authorid) references author(authorid), 5 foreign key(publisherid) references publisher(publisherid), 6 foreign key(categoryid) references category(categoryid)); Table created. SQL> desc catalog; Name Null? Type ------------------------------- -------- ---BOOKID NOT NULL NUMBER(38) TITLE VARCHAR2(20) AUTHORID NUMBER(38) PUBLISHERID NUMBER(38) CATEGORYID NUMBER(38) YEAR NUMBER(38) PRICE NUMBER(38) SQL> create table order_details(orderno int,bookid int,quantity int, 2 primary key(orderno,bookid), 3 foreign key(bookid) references catalog1(bookid)); Table created.

33

Lab Manual: DBMS Lab

SQL> desc order_details; Name ------------------------------ORDERNO BOOKID QUANTITY

Null? -------NOT NULL NOT NULL

Type ---NUMBER(38) NUMBER(38) NUMBER(38)

QUERY 2: Enter at least five tuples for each relation SQL> insert into author values(&aid,'&name','&city','&country'); Enter value for aid: 1001 Enter value for name: TERAS CHAN Enter value for city: CA Enter value for country: USA old 1: insert into author values(&aid,'&name','&city','&country') new 1: insert into author values(1001,'TERAS CHAN','CA','USA') 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value Enter value Enter value Enter value aid: 1004 name: KARTHIK B.P. city: NEW YORK country: USA into author values(&aid,'&name','&city','&country') into author values(1004,'KARTHIK B.P.','NEW YORK','USA') aid: 1003 name: M MANO city: CAIR country: CANADA into author values(&aid,'&name','&city','&country') into author values(1003,'M MANO','CAIR','CANADA') aid: 1002 name: STEVENS city: ZOMBI country: UGANDA into author values(&aid,'&name','&city','&country') into author values(1002,'STEVENS','ZOMBI','UGANDA')

for for for for

aid: 1005 name: WILLIAM STALLINGS city: LAS VEGAS country: USA

34

Lab Manual: DBMS Lab


old 1: insert into author values(&aid,'&name','&city','&country') new 1: insert into author values(1005,'WILLIAM STALLINGS','LAS VEGAS','USA') 1 row created. SQL> commit; Commit complete. SQL> select * from author; AUTHORID ---------1001 1002 1003 1004 1005 NAME -------------------TERAS CHAN STEVENS M MANO KARTHIK B.P. WILLIAM STALLINGS CITY -------------------CA ZOMBI CAIR NEW YORK LAS VEGAS COUNTRY --------------USA UGANDA CANADA USA USA

SQL> insert into publisher values(&pid,'&name','&city','&country'); Enter value for pid: 1 Enter value for name: PEARSON Enter value for city: NEW YORK Enter value for country: USA old 1: insert into publisher values(&pid,'&name','&city','&country') new 1: insert into publisher values(1,'PEARSON','NEW YORK','USA') 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for Enter value for pid: 2 name: EEE city: NEW SOUTH VALES country: USA into publisher values(&pid,'&name','&city','&country') into publisher values(2,'EEE','NEW SOUTH VALES','USA')

pid: 3 name: PHI city: DELHI country: INDIA into publisher values(&pid,'&name','&city','&country') into publisher values(3,'PHI','DELHI','INDIA')

pid: 4 name: WILLEY city: BERLIN country: GERMANY into publisher values(&pid,'&name','&city','&country') into publisher values(4,'WILLEY','BERLIN','GERMANY') pid: 5 name: MGH city: NEW YORK country: USA

35

Lab Manual: DBMS Lab


old 1: insert into publisher values(&pid,'&name','&city','&country') new 1: insert into publisher values(5,'MGH','NEW YORK','USA') 1 row created. SQL> commit; Commit complete. SQL> select * from publisher; PUBLISHERID ----------1 2 3 4 5 NAME -------------------PEARSON EEE PHI WILLEY MGH CITY -------------------NEW YORK NEW SOUTH VALES DELHI BERLIN NEW YORK COUNTRY --------------USA USA INDIA GERMANY USA

SQL> insert into category values(&cid,'&description'); Enter value for cid: 1001 Enter value for description: COMPUTER SCIENCE old 1: insert into category values(&cid,'&description') new 1: insert into category values(1001,'COMPUTER SCIENCE') 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> commit; Commit complete. SQL> select * from category; cid: 1002 description: ALGORITHM DESIGN into category values(&cid,'&description') into category values(1002,'ALGORITHM DESIGN')

cid: 1003 description: ELECTRONICS into category values(&cid,'&description') into category values(1003,'ELECTRONICS')

cid: 1004 description: PROGRAMMING into category values(&cid,'&description') into category values(1004,'PROGRAMMING')

cid: 1005 description: OPRATING SYSTEMS into category values(&cid,'&description') into category values(1005,'OPRATING SYSTEMS')

36

Lab Manual: DBMS Lab

CATEGORYID ---------1001 1002 1003 1004 1005

DESCRIPTION -------------------COMPUTER SCIENCE ALGORITHM DESIGN ELECTRONICS PROGRAMMING OPRATING SYSTEMS

SQL> insert into catalog values(&bid,'&title',&aid,&pid,&cid,&year,&price); Enter value for bid: 11 Enter value for title: Unix System Prg Enter value for aid: 1001 Enter value for pid: 1 Enter value for cid: 1001 Enter value for year: 2000 Enter value for price: 250.50 old 1: insert into catalog values(&bid,'&title',&aid,&pid,&cid,&year,&price) new1: insert into catalog values(11,'Unix System Prg',1001,1,1001,2000,250.5 0) 1 row created. SQL> / Enter value for bid: 12 Enter value for title: Digital Signals Enter value for aid: 1002 Enter value for pid: 2 Enter value for cid: 1003 Enter value for year: 2001 Enter value for price: 425.22 old 1: insert into catalog values(&bid,'&title',&aid,&pid,&cid,&year,&price) new1: insert into catalog values(12,'Digital Signals',1002,2,1003,2001,425.2 2) 1 row created. SQL> / Enter value for bid: 13 Enter value for title: Logic Design Enter value for aid: 1003 Enter value for pid: 3 Enter value for cid: 1002 Enter value for year: 1999 Enter value for price: 225 old 1: insert into catalog values(&bid,'&title',&aid,&pid,&cid,&year,&price) new 1: insert into catalog values(13,'Logic Design',1003,3,1002,1999,225) 1 row created.

SQL> / Enter value Enter value Enter value Enter value

for for for for

bid: 14 title: Server Prg aid: 1004 pid: 4

37

Lab Manual: DBMS Lab


Enter value for cid: 1004 Enter value for year: 2001 Enter value for price: 332.56 old 1: insert into catalog values(&bid,'&title',&aid,&pid,&cid,&year,&price) new 1: insert into catalog values(14,'Server Prg',1004,4,1004,2001,332.56) 1 row created. SQL> / Enter value for bid: 15 Enter value for title: Linux OS Enter value for aid: 1005 Enter value for pid: 5 Enter value for cid: 1005 Enter value for year: 2003 Enter value for price: 325.58 old 1: insert into catalog values(&bid,'&title',&aid,&pid,&cid,&year,&price) new 1: insert into catalog values(15,Linux OS',1005,5,1005,2003,325.58) 1 row created. SQL> / Enter value for bid: 16 Enter value for title: C++ Bible Enter value for aid: 1005 Enter value for pid: 5 Enter value for cid: 1001 Enter value for year: 2000 Enter value for price: 525.58 old 1: insert into catalog values(&bid,'&title',&aid,&pid,&cid,&year,&price) new 1: insert into catalog values(16,'C++ Bible',1005,5,1001,2000,525.58) 1 row created. SQL> / Enter value for bid: 17 Enter value for title: COBOL Handbook Enter value for aid: 1005 Enter value for pid: 4 Enter value for cid: 1001 Enter value for year: 2000 Enter value for price: 657.58 old 1: insert into catalog values(&bid,'&title',&aid,&pid,&cid,&year,&price) new1: insert into catalog values(17,'COBOL Handbook',1005,4,1001,2000,657.58 ) 1 row created. SQL> commit; Commit complete. SQL> select * from catalog; BOOKID TITLE AUTHORID PUBLISHERID CATEGORYID YEAR ---------- ---------------- -------- ----------- ---------- ---11 Unix System Prg 1001 1 1001 2000 PRICE ---------251

38

Lab Manual: DBMS Lab


12 13 14 15 16 17 Digital Signals Logic Design Server Prg Linux OS C++ Bible COBOL Handbook 1002 1003 1004 1005 1005 1005 2 3 4 5 5 4 1003 1002 1004 1005 1001 1001 2001 1999 2001 2003 2000 2000 425 225 333 326 526 658

7 rows selected. SQL> insert into order_details values(&orderno,&bookid,&qunatity); Enter value for orderno: 1 Enter value for bookid: 11 Enter value for qunatity: 5 old 1: insert into order_details values(&orderno,&bookid,&qunatity) new 1: insert into order_details values(1,11,5) 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> commit; Commit complete. SQL> select * from order_details; ORDERNO BOOKID QUANTITY ---------- ---------- ---------1 11 5 2 12 8 orderno: 2 bookid: 12 qunatity: 8 into order_details values(&orderno,&bookid,&qunatity) into order_details values(2,12,8)

orderno: 3 bookid: 13 qunatity: 15 into order_details values(&orderno,&bookid,&qunatity) into order_details values(3,13,15)

orderno: 4 bookid: 14 qunatity: 22 into order_details values(&orderno,&bookid,&qunatity) into order_details values(4,14,22)

orderno: 5 bookid: 15 qunatity: 3 into order_details values(&orderno,&bookid,&qunatity) into order_details values(5,15,3)

39

Lab Manual: DBMS Lab


3 4 5 13 14 15 15 22 3

QUERY 3: Give the details of the authors who have 2 or more books in the catalog and the price of the books in the catalog and the year of publication is after 2000. SQL> 2 3 4* select * from author where authorid in(select authorid from catalog1 group by authorid having count(*) > 2 and authorid in( select authorid from catalog1 where price > (select avg(price) from catalog1) and year>=2000))

AUTHORID NAME CITY COUNTRY ---------- -------------------- -------------------- --------------1005 WILLIAM STALLINGS LAS VEGAS USA QUERY 4: Find the author of the book which has maximum sales. SQL> 2 3 4 select select bookid select name from author where authorid in( authorid from catalog1 where bookid in(select from order_details where quantity=( max(quantity) from order_details)));

NAME -------------------KARTHIK B.P. QUERY 5: Demonstrate how you increase the price of books published by a specific publisher by 10%. SQL> select bookid,title,price,price*1.1 from catalog1; BOOKID TITLE PRICE PRICE*1.1 ---------- -------------------- ---------- ---------11 Unix System Prg 251 276.1 12 Digital Signals 425 467.5 13 Logic Design 225 247.5 14 Server Prg 333 366.3 15 Linux OS 326 358.6 16 C++ Bible 526 578.6 17 COBOL Handbook 658 723.8 7 rows selected. SQL> select bookid,title,price,price*1.1 from catalog1 2 where publisherid in(select publisherid from publisher 3 where name='PEARSON'); BOOKID TITLE PRICE PRICE*1.1 ---------- -------------------- ---------- ---------11 Unix System Prg 251 276.1 PROGRAM 5: BANKING ENTERPRISE DATABASE V. Consider the following database for a banking enterprise. BRANCH (branch-name: String, branch-city: String, assets: real)

40

Lab Manual: DBMS Lab


ACCOUNTS (accno: int, branch-name: String, balance: real) DEPOSITOR (customer-name: String, customer-street: String, customer-city: String) LOAN (loan-number: int, branch-name: String, amount: real) BORROWER (customer-name: String, loan-number: int) i) Create the above tables by properly specifying the primary keys and the foreign keys. ii) Enter at least five tuples for each relation. iii) Find all the customers who have at least two accounts at the Main branch. iv) Find all the customers who have an account at all the branches located in a specific city. v) Demonstrate how you delete all account tuples at every branch located in a specific city. vi) Generate suitable reports. vii) Create suitable front end for querying and displaying the results. BRANCH Branchname Branchcity Assets

ACCOUNT Accno Branchname Balance

DEPOSITOR Customername Accno

CUSTOMER Customername Customer-street City

LOAN Loannumber Branchname Amount

BORROWER Customername loannumber QUERY 1: Create the above tables by properly specifying the primary keys and the foreign keys. SQL> create table branch(branch_name varchar(20) primary key, 2 branch_city varchar(10),assets real); Table created.

41

Lab Manual: DBMS Lab

SQL> desc branch; Name Null? ------------------------------- -------BRANCH_NAME NOT NULL BRANCH_CITY ASSETS

Type ---VARCHAR2(20) VARCHAR2(10) FLOAT(63)

SQL> create table account(accno int primary key,branch_name varchar(20), 2 balance real,foreign key(branch_name) references branch(branch_name)); Table created. SQL> desc account; Name Null? ------------------------------- -------ACCNO NOT NULL BRANCH_NAME BALANCE Type ---NUMBER(38) VARCHAR2(20) FLOAT(63)

SQL> create table customer(customer_name varchar(20) primary key, 2 customer_street varchar(20),cust_city varchar(20)); Table created. SQL> desc customer; Name Null? ------------------------------- -------CUSTOMER_NAME NOT NULL CUSTOMER_STREET CUST_CITY Type ---VARCHAR2(20) VARCHAR2(20) VARCHAR2(20)

SQL> create table depositor(customer_name varchar(20),accno int, 2 foreign key(customer_name) references customer(customer_name), 3 foreign key(accno) references account(accno)); Table created. SQL> desc depositor; Name Null? ------------------------------- -------CUSTOMER_NAME ACCNO Type ---VARCHAR2(20) NUMBER(38)

SQL> create table loan(loan_no int primary key, 2 branch_name varchar(20),amount real, 3 foreign key(branch_name) references branch(branch_name)); Table created. SQL> desc loan; Name Null? Type ------------------------------- -------- ---LOAN_NO NOT NULL NUMBER(38) BRANCH_NAME VARCHAR2(20) AMOUNT FLOAT(63) SQL> create table borrower(customer_name varchar(20),loan_no int, 2 foreign key(customer_name) references customer(customer_name), 3 foreign key(loan_no) references loan(loan_no)); Table created.

42

Lab Manual: DBMS Lab


SQL> desc borrower; Name Null? ------------------------------- -------CUSTOMER_NAME LOAN_NO

Type ---VARCHAR2(20) NUMBER(38)

QUERY 2: Enter at least five tuples for each relation SQL> insert into branch values('&bname','&bcity',&assets); Enter value for bname: SBI PD NAGAR Enter value for bcity: BANGALORE Enter value for assets: 200000 old 1: insert into branch values('&bname','&bcity',&assets) new 1: insert into branch values('SBI PD NAGAR','BANGALORE',200000) 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> commit; Commit complete. SQL> select * from branch; BRANCH_NAME BRANCH_CIT ASSETS -------------------- ---------- ---------SBI PD NAGAR BANGALORE 200000 bname: SBI RAJAJI NAGAR bcity: BANGALORE assets: 500000 into branch values('&bname','&bcity',&assets) into branch values('SBI RAJAJI NAGAR','BANGALORE',500000)

bname: SBI JAYANAGAR bcity: BANGALORE assets: 660000 into branch values('&bname','&bcity',&assets) into branch values('SBI JAYANAGAR','BANGALORE',660000)

bname: SBI VIJAY NAGAR bcity: BANGALORE assets: 870000 into branch values('&bname','&bcity',&assets) into branch values('SBI VIJAY NAGAR','BANGALORE',870000)

bname: SBI HOSAKEREHALLI bcity: BANGALORE assets: 550000 into branch values('&bname','&bcity',&assets) into branch values('SBI HOSAKEREHALLI','BANGALORE',550000)

43

Lab Manual: DBMS Lab


SBI SBI SBI SBI RAJAJI NAGAR JAYANAGAR VIJAY NAGAR HOSAKEREHALLI BANGALORE BANGALORE BANGALORE BANGALORE 500000 660000 870000 550000

SQL> insert into account values(&accno,'&bname',&balance); Enter value for accno: 1234602 Enter value for bname: SBI HOSAKEREHALLI Enter value for balance: 5000 old 1: insert into account values(&accno,'&bname',&balance) new 1: insert into account values(1234602,'SBI HOSAKEREHALLI',5000) 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. accno: 1234603 bname: SBI VIJAY NAGAR balance: 5000 into account values(&accno,'&bname',&balance) into account values(1234603,'SBI VIJAY NAGAR',5000)

accno: 1234604 bname: SBI JAYANAGAR balance: 5000 into account values(&accno,'&bname',&balance) into account values(1234604,'SBI JAYANAGAR',5000)

accno: 1234605 bname: SBI RAJAJI NAGAR balance: 10000 into account values(&accno,'&bname',&balance) into account values(1234605,'SBI RAJAJI NAGAR',10000)

accno: 1234503 bname: SBI VIJAY NAGAR balance: 40000 into account values(&accno,'&bname',&balance) into account values(1234503,'SBI VIJAY NAGAR',40000)

SQL> / Enter value for accno: 1234504 Enter value for bname: SBI PD NAGAR Enter value for balance: 4000 old 1: insert into account values(&accno,'&bname',&balance) new 1: insert into account values(1234504,'SBI PD NAGAR',4000) 1 row created. SQL> commit; Commit complete. SQL> select * from account;

44

Lab Manual: DBMS Lab


ACCNO ---------1234602 1234603 1234604 1234605 1234503 1234504 BRANCH_NAME BALANCE -------------------- ---------SBI HOSAKEREHALLI 5000 SBI VIJAY NAGAR 5000 SBI JAYANAGAR 5000 SBI RAJAJI NAGAR 10000 SBI VIJAY NAGAR 40000 SBI PD NAGAR 4000

6 rows selected. SQL> insert into customer values('&cname','&cstreet','&ccity'); Enter value for cname: KEZAR Enter value for cstreet: M G ROAD Enter value for ccity: BANGALORE old 1: insert into customer values('&cname','&cstreet','&ccity') new 1: insert into customer values('KEZAR','M G ROAD','BANGALORE') 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert cname: LAL KRISHNA cstreet: ST MKS ROAD ccity: BANGALORE into customer values('&cname','&cstreet','&ccity') into customer values('LAL KRISHNA','ST MKS ROAD','BANGALORE')

cname: RAHUL cstreet: AUGSTEN ROAD ccity: BANGALORE into customer values('&cname','&cstreet','&ccity') into customer values('RAHUL','AUGSTEN ROAD','BANGALORE')

cname: LALLU cstreet: V S ROAD ccity: BANGALORE into customer values('&cname','&cstreet','&ccity') into customer values('LALLU','V S ROAD','BANGALORE')

cname: FAIZAL cstreet: RESEDENCY ROAD ccity: BANGALORE into customer values('&cname','&cstreet','&ccity') into customer values('FAIZAL','RESEDENCY ROAD','BANGALORE')

cname: RAJEEV cstreet: DICKNSN ROAD ccity: BANGALORE into customer values('&cname','&cstreet','&ccity')

45

Lab Manual: DBMS Lab


new 1: insert into customer values('RAJEEV','DICKNSN ROAD','BANGALORE') 1 row created. SQL> commit; Commit complete. SQL> select * from customer; CUSTOMER_NAME -------------------KEZAR LAL KRISHNA RAHUL LALLU FAIZAL RAJEEV 6 rows selected. CUSTOMER_STREET -------------------M G ROAD ST MKS ROAD AUGSTEN ROAD V S ROAD RESEDENCY ROAD DICKNSN ROAD CUST_CITY -------------------BANGALORE BANGALORE BANGALORE BANGALORE BANGALORE BANGALORE

SQL> insert into depositor values('&cname',&accno); Enter value for cname: KEZAR Enter value for accno: 1234602 old 1: insert into depositor values('&cname',&accno) new 1: insert into depositor values('KEZAR',1234602) 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert cname: LAL KRISHNA accno: 1234603 into depositor values('&cname',&accno) into depositor values('LAL KRISHNA',1234603)

cname: RAHUL accno: 1234604 into depositor values('&cname',&accno) into depositor values('RAHUL',1234604)

cname: LALLU accno: 1234605 into depositor values('&cname',&accno) into depositor values('LALLU',1234605)

cname: LAL KRISHNA accno: 1234503 into depositor values('&cname',&accno) into depositor values('LAL KRISHNA,1234503) cname: RAJEEV accno: 1234504 into depositor values('&cname',&accno) into depositor values('RAJEEV',1234504)

46

Lab Manual: DBMS Lab


1 row created. SQL> commit; Commit complete. SQL> select * from depositor; CUSTOMER_NAME ACCNO -------------------- ---------KEZAR 1234602 LAL KRISHNA 1234603 RAHUL 1234604 LALLU 1234605 LAL KRISHNA 1234503 RAJEEV 1234504 6 rows selected. SQL> insert into loan values(&loanno,'&bname',&amount); Enter value for loanno: 10011 Enter value for bname: SBI JAYANAGAR Enter value for amount: 10000 old 1: insert into loan values(&loanno,'&bname',&amount) new 1: insert into loan values(10011,'SBI JAYANAGAR',10000) 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for Enter value for old 1: insert new 1: insert 1 row created. loanno: 10012 bname: SBI VIJAY NAGAR amount: 5000 into loan values(&loanno,'&bname',&amount) into loan values(10012,'SBI VIJAY NAGAR',5000)

loanno: 10013 bname: SBI HOSAKEREHALLI amount: 20000 into loan values(&loanno,'&bname',&amount) into loan values(10013,'SBI HOSAKEREHALLI',20000)

loanno: 10014 bname: SBI PD NAGAR amount: 15000 into loan values(&loanno,'&bname',&amount) into loan values(10014,'SBI PD NAGAR',15000)

SQL> / Enter value for Enter value for Enter value for old 1: insert

loanno: 10015 bname: SBI RAJAJI NAGAR amount: 25000 into loan values(&loanno,'&bname',&amount)

47

Lab Manual: DBMS Lab


new 1: insert into loan values(10015,'SBI RAJAJI NAGAR',25000) 1 row created. SQL> commit; Commit complete. SQL> select * from loan; LOAN_NO BRANCH_NAME AMOUNT ---------- -------------------- ---------10011 SBI JAYANAGAR 10000 10012 SBI VIJAY NAGAR 5000 10013 SBI HOSAKEREHALLI 20000 10014 SBI PD NAGAR 15000 10015 SBI RAJAJI NAGAR 25000 SQL> insert into borrower values('&cname',&loanno); Enter value for cname: KEZAR Enter value for loanno: 10011 old 1: insert into borrower values('&cname',&loanno) new 1: insert into borrower values('KEZAR',10011) 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. SQL> / Enter value for Enter value for old 1: insert new 1: insert 1 row created. cname: LAL KRISHNA loanno: 10012 into borrower values('&cname',&loanno) into borrower values('LAL KRISHNA',10012)

cname: RAHUL loanno: 10013 into borrower values('&cname',&loanno) into borrower values('RAHUL',10013)

cname: LALLU loanno: 10014 into borrower values('&cname',&loanno) into borrower values('LALLU',10014)

cname: FAIZAL loanno: 10015 into borrower values('&cname',&loanno) into borrower values('FAIZAL',10015)

SQL> commit; Commit complete. SQL> select * from borrower; CUSTOMER_NAME LOAN_NO -------------------- ---------KEZAR 10011

48

Lab Manual: DBMS Lab


LAL KRISHNA RAHUL LALLU LAL KRISHNA 10012 10013 10014 10015

QUERY 3: Find all the customers who have at least two accounts at the Main branch. SQL> 2 3 4 5 6 select customer_name from depositor where accno in( select accno from depositor where accno in( select accno from account where branch_name in( select branch_name from account where branch_name='SBI VIJAY NAGAR' group by branch_name having count(*) > 1))) group by customer_name having count(*) > 1

CUSTOMER_NAME -------------------LAL KRISHNA QUERY 4: Find all the customers who have an account at all the branches located in a specific city. SQL> select customer_name,accno from depositor where accno in( 2 select accno from account where branch_name in( 3 select branch_name from branch where branch_city='BANGALORE')); CUSTOMER_NAME ACCNO -------------------- ---------KEZAR 1234602 LAL KRISHNA 1234603 RAHUL 1234604 LALLU 1234605 LAL KRISHNA 1234503 RAJEEV 1234504 6 rows selected. QUERY 5: Demonstrate how you delete all account tuples at every branch located in a specific city. SQL> delete from account where branch_name=(select branch_name 2 from branch where branch_city=&city); Enter value for city: BANGALORE old 2: where branch_city=&city new 6: where brach_city=BANGALORE 1 row deleted.

49

Вам также может понравиться