Anjuman Engineering College, Bhatkal 1 Database Applications Laboratory

1. Consider the Insurance database given below. The primary keys are underlined and the data types are specified: 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,damage-amount:int) i) create the above tables by properly specifying the primary keys and the foreign keys ii) Enter atleast five tuples for each relation iii) Demonstrate how you a. Update the damage amount for the car with a specific regno in accident with report number 12 to 25000 b. Add a new accident to the database iv) Find the total number of people who owned cars that were involved in accidents in 2006. v) Find the number of accidents in which cars belonging to a specific model were involved. vi) Generation of suitable reports vii) Create suitable front end for querying and display the results create table person ( driverid varchar(5) primary key, name varchar(30), address varchar(50) ); create table car ( regno varchar(5) primary key, model varchar(25), year int ); create table accident ( reportno int primary key, date1 date, location varchar(30) ); create table owns ( driverid references person, regno references car );

Anjuman Engineering College, Bhatkal 2 Database Applications Laboratory

create table participated ( driverid references person, regno references car, reportno references accident, damages int ); insert into person values (1,'abc','hkbkce,nagawara'); insert into person values (2,'bcd','atria,yelahanka'); insert into person values (3,'ade','ramahiah,near iisc'); insert into person values (4,'cfg','mvjce,whitefield'); insert into person values (5,'rte','pesit,somewhere'); insert into car values ('a1','merc',2007); insert into car values ('a2','porsche',2005); insert into car values ('b2','rolls royce',2006); insert into car values ('b4','ferrari',1999); insert into car values ('c1','bentley',2000); insert into car values ('d2','maybach',2007); insert into accident values (1,'1-jan-2006','domlur'); insert into accident values (2,'28-mar-2006','m.g.road'); insert into accident values (3,'2-dec-2006','r.t.nagar'); insert into accident values (4,'5-jan-2007','yelahanka'); insert into accident values (5,'26-jan-2007','koramangla'); insert into accident values (6,'4-feb-2007','majestic'); insert into owns values (1,'a1'); insert into owns values (2,'a2'); insert into owns values (2,'c1'); insert into owns values (3,'b2'); insert into owns values (4,'b4'); insert into owns values (5,'d2'); insert into participated values (1,'a1',1,500); insert into participated values (2,'a2',1,2000); insert into participated values (3,'b2',1,1000); insert into participated values (1,'a1',2,1500); insert into participated values (4,'c1',2,800); insert into participated values (5,'d2',3,750); insert into participated values (2,'c1',3,600); insert into participated values (1,'a1',3,200); insert into participated values (5,'d2',4,1000); insert into participated values (2,'a2',5,1200); insert into participated values (3,'b2',6,10000); insert into participated values (2,'a1',6,5000);

---------------.----------------.nagar yelahanka koramangla majestic .---------------1 a1 1 500 2 a2 1 2000 3 b2 1 1000 1 a1 2 1500 4 c1 2 800 5 d2 3 750 2 c1 3 600 1 a1 3 200 LOCATION ----------------------domlur m. Bhatkal 3 Database Applications Laboratory select * from person.---------1 abc 2 bcd 3 ade 4 cfg 5 rte ADDRESS ---------------------hkbkce. DRIVERID REGNO -------------.Anjuman Engineering College.----------.somewhere select * from car. DRIVERID REGNO REPORTNO DAMAGES ---------------.g.road r. REGNO MODEL YEAR ----------. REPORTNO DATE1 ----------------.-------------1 01-JAN-06 2 28-MAR-06 3 02-DEC-06 4 05-JAN-07 5 26-JAN-07 6 04-FEB-07 select * from owns.nagawara atria.yelahanka ramahiah.-----------a1 merc 2007 a2 porsche 2005 b2 rolls royce 2006 b4 ferrari 1999 c1 bentley 2000 d2 maybach 2007 select * from accident.t.near iisc mvjce.----------1 a1 2 a2 2 c1 3 b2 4 b4 5 d2 select * from participated. DRIVERID NAME ---------------.whitefield pesit.

t.Anjuman Engineering College. 1 row updated select * from participated.'a1'. Bhatkal 4 Database Applications Laboratory 5 2 3 2 d2 a2 b2 a1 4 5 6 6 1000 1200 10000 5000 iii.-------------1 01-JAN-06 2 28-MAR-06 3 02-DEC-06 4 05-JAN-07 5 26-JAN-07 6 04-FEB-07 7 16-MAR-07 LOCATION ----------------------domlur m.road r.'nagawara').----------------.7.'16-mar-2007'.----------. REPORTNO DATE1 ----------------. 1 row updated select * from accident.nagar yelahanka koramangla majestic nagawara .b Add a new accident to the database insert into accident values (7.g.a Update the damage amount for the car with a specific regno in accident with report number 12 to 25000 update participated set damages=25000 where reportno=4 and regno='d2'.15000). DRIVERID REGNO REPORTNO DAMAGES ---------------. 1 row updated insert into participated values (2.---------------1 a1 1 500 2 a2 1 2000 3 b2 1 1000 1 a1 2 1500 4 c1 2 800 5 d2 3 750 2 c1 3 600 1 a1 3 200 5 d2 4 25000 2 a2 5 1200 3 b2 6 10000 2 a1 6 5000 iii.

Find the number of accidents in which cars belonging to a specific model were involved.regno. COUNT(*) -------------2 . COUNT(DISTINCTP. Find the total number of people who owned cars that were involved in accidents in 2006 select count(distinct p.---------------1 a1 1 500 2 a2 1 2000 3 b2 1 1000 1 a1 2 1500 4 c1 2 800 5 d2 3 750 2 c1 3 600 1 a1 3 200 5 d2 4 25000 2 a2 5 1200 3 b2 6 10000 2 a1 6 5000 2 a1 7 15000 iv.DRIVERID) --------------------------------------------4 v.participated p where model='porsche' and c.driverid. Bhatkal 5 Database Applications Laboratory select * from participated.----------.reportno and p. select count(*) from car c.driverid) from accident a. DRIVERID REGNO REPORTNO DAMAGES ---------------.driverid=p.regno=p.regno and o.Anjuman Engineering College.reportno=p.participated p where date1 like '%06' and a.----------------.owns o.regno=o.

ii) Enter at least five tuples for each relation. Ord-Amt: int) ORDER-ITEM (Order #: int. city varchar(15) ). AVG_ORDER_AMT. cname varchar(10). Generation of suitable reports. NO_OF_ORDERS. Cname: string. List the Order# for the orders that were shipped from all the warehouses that the company has in a specific city. odate date. create table oitem ( ono references order1. create table order1 ( ono int primary key. Create a suitable front end for querying and displaying the results. City: string) ORDER (Order #: int. Produce a listing: CUSTNAME. Item #: int. where the middle column is the total number of orders by the customer and the last column is the average order amount for that customer. ino references item on delete set null. cno references customer. uprice int ). Odate: date.Anjuman Engineering College. Unit Price: int) SHIPMENT (Order #: int. CUSTOMER (Cust #: int. qty int ). Demonstrate how you delete Item# 10 from the ITEM table and make that field null in the ORDER-ITEM table. Bhatkal 6 Database Applications Laboratory 2. oamt int ). Consider the following relations for an order processing database application in a company. Ship-Date: date) WAREHOUSE (Warehouse #: int. qty: int) ITEM (Item #: int. Warehouse #: int. City: string) i) iii) iv) v) vi) vii) Create the above tables by properly specifying the primary keys and the foreign keys. create table item ( ino int primary key. . Cust #: int. create table customer ( cno int primary key.

insert into oitem values(1.'adf'.2.1.'3-jan-2006').'def'.'mysore').'10-jan-2007'. insert into item values(5.3).2500). insert into order1 values(6.5. insert into order1 values(4.2500).100. insert into warehouse values(103.'bangalore').'abc'. insert into customer values(5. wno references warehouse. insert into item values(4.500).'bangalore'). insert into customer values(2. insert into warehouse values(104.800).'kolkata'). city varchar(15) ). insert into order1 values(1.4. insert into oitem values(7. insert into order1 values(2.'13-jun-2006').'5-jan-2007'.1.'chennai'). insert into oitem values(3.20).1.'mumbai'). insert into customer values(3.2. insert into order1 values(5. insert into order1 values(3. insert into oitem values(6.3. insert into oitem values(2.1.10000).'12-jun-2006'.40). insert into item values(1.700).4. Bhatkal 7 Database Applications Laboratory create table warehouse ( wno int primary key. insert into warehouse values(101.'kolkata').'26-mar-2006'.3. sdate date ).300).5).'15-sep-2006'.'efg'.'1-jan-2006'. insert into oitem values(4. insert into order1 values(7.'mumbai').9000). insert into customer values(1.1).100. insert into shipment values(1.2400).5000).'3-mar-2007'.4.5.'mysore'). insert into shipment values(2. insert into warehouse values(100.3500). insert into shipment values(3. insert into customer values(4. insert into item values(2. .3.101.20000). insert into warehouse values(102.Anjuman Engineering College.'chennai'). insert into oitem values(5.2).'cde'. insert into item values(3.'28-mar-2006'). create table shipment ( ono references order1.30).

Anjuman Engineering College. Bhatkal 8 Database Applications Laboratory insert into shipment values(4. insert into shipment values(7. insert into shipment values(6. ONO INO QTY ---------. select * from customer.---------.---------. ONO ODATE CNO OAMT ---------.---------1 01-JAN-06 1 20000 2 26-MAR-06 2 10000 3 12-JUN-06 1 5000 4 15-SEP-06 3 9000 5 05-JAN-07 4 2500 6 10-JAN-07 4 2400 7 03-MAR-07 5 3500 select * from item.---------1 1 40 2 1 20 3 3 2 5 3 1 4 2 30 6 4 3 7 5 5 .104.103.'18-sep-2006'). insert into shipment values(5.'13-jan-2007'). INO UPRICE ---------.--------------1 abc bangalore 2 cde mysore 3 def chennai 4 efg mumbai 5 adf kolkata select * from order1.---------------.103.102.'3-mar-2007'). CNO CNAME CITY ---------.---------.---------1 500 2 300 3 2500 4 800 5 700 select * from oitem.'11-jan-2007').

List the Order# for the orders that were shipped from all the warehouses that the company has in a specific city.Anjuman Engineering College.qty).wno.city='mumbai'. order1 o.count(q.-------.cname.ono from warehouse w. CITY WNO ONO --------------. Bhatkal 9 Database Applications Laboratory select * from warehouse. s.---------mumbai 102 4 .avg(oamt) from customer c. NO_OF_ORDERS. select c. ONO WNO SDATE ---------.--------------100 bangalore 101 chennai 102 mumbai 103 kolkata 104 mysore select * from shipment. select w. Produce a listing: CUSTNAME.cno group by cname. s. shipment s where w. where the middle column is the total number of orders by the customer and the last column is the average order amount for that customer.ono=o. CNAME COUNT(Q.city.---------.---------------------abc 2 adf 1 cde 1 def 1 efg 2 AVG(OAMT) -------------------12500 3500 10000 9000 2450 iv. AVG_ORDER_AMT.-----------1 100 03-JAN-06 2 100 28-MAR-06 3 101 13-JUN-06 4 102 18-SEP-06 5 103 11-JAN-07 6 104 13-JAN-07 7 103 03-MAR-07 iii. oitem q where q.ono and c.cno=o.QTY) -----------.wno and w. WNO CITY ---------.wno=s.

INO UPRICE ---------.Anjuman Engineering College.---------1 500 2 300 3 2500 4 800 . Bhatkal 10 Database Applications Laboratory v. Demonstrate how you delete Item# 10 from the ITEM table and make that field null in the ORDER-ITEM table delete from item where ino=5. 1 row deleted select * from item.

create table course ( cno int primary key. Consider the following database of student enrollement in courses and books adopted for each course . v) List any department that has all its adopted books published by specific publisher.book_isbn. cname varchar(10). . title varchar(15). ii) Enter atleast 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. book_isbn :int) TEXT( book_isbn : int . bdate date ). cname : string . author : string). vi) Generation of suitable reports. major varchar(10). STUDENT (regno :string . Bhatkal 11 Database Applications Laboratory 3. sem : int .book-title) in the alphabetical order for courses offered by the cs department that use more than 2 books. bdate : int) COURSE (course# : int . name varchar(10). book-title : string . vii) Create suitable front end for querying and display the results create table student ( regno varchar(5) primary key. marks : int ) BOOK_ADAPTION ( course#: int . sem int primary key. course#: int . iv) Produce a list of text books( include course # . publisher varchar(10). i) Create the above tables by properly specifying the primary keys and the foreign key . cno references course. dept : string) ENROLL ( regno : string . create table enroll ( regno references student. marks int ). sem : int . major : string . author varchar(10) ). publisher : string . dept varchar(10) ). name : string .Anjuman Engineering College. create table text ( isbn int primary key.

'ise'.'16-aug-1987'). insert into text values(103.3.'ise'.'oracle'. insert into course values(5.3.'fs'. insert into bad values(5.1. insert into student values('is48'.'oracle'.'othman').7.net'. insert into bad values(1. insert into enroll values('cs42'.4. select * from student.98). REGNO NAME MAJOR BDATE ---------.'cse'.net'.'def'. insert into enroll values('ee37'.6. insert into enroll values('is48'.'mikhil'). insert into course values(3. insert into bad values(1.'pearson'.105).'lpe'.'.'mujeeb'.'infosci').50). insert into course values(1.90).'majid'.'wajid'. insert into text values(102. insert into course values(4.---------.'mis'. insert into student values('cs42'.6.'02-sep-1986').5.'cse'.'mujeeb').104).'cse'.------------cs42 mikhil cse 17-DEC-86 cs48 mujeeb cse 02-SEP-86 ec26 pradeep cse 16-AUG-87 ee37 majid ise 28-MAY-86 is48 wajid ise 28-MAY-86 .5.7. insert into text values(105. sem references enroll.'infosci'). isbn references text ).'let us c'.6.'28-may-1986').'.4. insert into bad values(4.102).4. insert into student values('cs48'.'lpe'. insert into course values(2. insert into enroll values('ec26'.'fahad').'abc'.'computer').97). insert into enroll values('cs48'.'j2ee'.'j2ee'.103). insert into student values('ee37'.Anjuman Engineering College.2.'pradeep'. insert into text values(104. insert into text values(101.'mikhil'.6. Bhatkal 12 Database Applications Laboratory create table bad ( cno references course.101). insert into student values('ec26'.------------.'c++'.'computer').80).'17-dec-1986'). insert into bad values(1.'28-may-1986').'computer').'naushad').

--------------101 let us c lpe fahad 102 c++ abc mujeeb 103 oracle def othman 104 .-----------cs42 1 6 98 cs48 2 3 97 ec26 5 5 50 is48 3 7 90 ee37 4 4 80 select * from text.--------------101 let us c lpe fahad 102 c++ abc mujeeb 103 oracle def othman 104 .-------------.-----------1 .7. Bhatkal 13 Database Applications Laboratory select * from course.--------------.-----------------. insert into bad values(2.---------. ISBN TITLE PUBLISHER AUTHOR ---------.--------------. ISBN TITLE PUBLISHER AUTHOR ---------.-----------------. select * from text. insert into text values(106.Anjuman Engineering College.'pearson'.106).---------. CNO SEM ISBN ---------.net computer 2 j2ee computer 3 mis infosci 4 fs infosci 5 oracle computer select * from enroll.net lpe naushad 105 j2ee pearson mikhil 106 JAVA pearson Avril . CNO CNAME DEPT ---------.'JAVA'.'Avril'). REGNO CNO SEM MARKS -----------.---------1 6 101 1 6 103 1 6 102 4 4 104 5 7 105 iii.net lpe naushad 105 j2ee pearson mikhil select * from bad.Demonstrate how you add a new text book to the database and make this book be adopted by some department.---------.

---------1 6 101 1 6 103 1 6 102 4 4 104 5 7 105 2 7 106 iv.cno AND b. List any department that has all its adopted books published by specific publisher.cno.isbn=t.--------------.b. CNO TITLE ISBN ---------. SELECT s.isbn AND s.cno=b.cno=s. bad b.---------1 c++ 102 1 let us c 101 1 oracle 103 v.cno group by b.book_isbn.dept.title.isbn and publisher='lpe'. Produce a list of text books( include course # .dept='computer' AND b.book-title) in the alphabetical order for courses offered by the cs department that use more than 2 books.publisher from course s.cno from bad b. Bhatkal 14 Database Applications Laboratory select * from bad. text t where s.isbn=b. select s. DEPT ------------computer infosci PUBLISHER -------------------lpe lpe .course s where b.---------. t.cno and t.bad b.Anjuman Engineering College.title.t. CNO SEM ISBN ---------.text t where s.cno=b.cno having count(*)>2) order by t.isbn FROM course s.cno in (select b.

author-id: int. iv. name varchar(15) . Name: string.Anjuman Engineering College. Quantity: int) i. . Bhatkal 15 Database Applications Laboratory 4. create table author ( aid int primary key. title varchar(15). country varchar(15) ). City: string. Description: string) ORDER-DETAILS (Order-no : int. create table catalog ( bid int primary key. Give the details of the authors who have 2 or more books in the catalog and the price of the books is greater than the average price of the books in the catalog and the year of publication is after 2000. country varchar(15) ). Consider the following relations for the details maintained by a book dealer. Create the above tables by properly specifying the primary keys and the foreign keys. name varchar(15). Create a suitable front end for querying and displaying the results. Name: string. Publisher-id: int. iii. Generation of suitable reports. description varchar(15) ). pid references publisher. vii. v. Year: int. Category-id: int. aid references author. Demonstrate how you increase the price of books published by a specific publisher by 10%. year int. create table category ( cid int primary key. city varchar(15) . Country: string) CATALOG (Book-id: int. title: string. ii. City: string. Book-id: int. Country: string) PUBLISHER (Publisher-id: int. Find the author of the book which has maximum sales. Enter at least five tuples for each relation. price int ). city varchar(15). create table publisher ( pid int primary key. cid references category. AUTHOR (Author-id: int. vi. Price: int) CATEGORY (Category-id: int.

1).'science').104. insert into odetails values (1.'electrical'). insert into author values (5.--------------.'mumbai'.'lib4'. insert into category values (1004.114.105.3.'maj'.'abc'.2.'lib3'.'xyz'.'pearson'.200).2003. insert into catalog values (115.1.100).103.'ind').2). Bhatkal 16 Database Applications Laboratory create table odetails ( ono int.101.1002. insert into catalog values (118.'ind'). insert into category values (1001.1001.'anan'.2007.2000.'waj'. insert into odetails values (3.'tata'.4.'che'.'aus').'lib7'.1004.Anjuman Engineering College.103. insert into catalog values (117.'tri'. insert into publisher values (105.'ind'). insert into catalog values (114.350).'ind').2007. insert into publisher values (101.2006. insert into author values (1.'bang'.1003.112.--------------1 mik bang ind 2 muj bang ind 3 prad tri aus 4 maj anan ame 5 waj anan euro .'euro').'prad'.'bang'. insert into category values (1003.2.'bang'. insert into odetails values (6.1002.113. qty int ).'lib5'.1001.500).2).102.105. insert into publisher values (104.1). insert into odetails values (5.'muj'.5.'sapna'.--------------.2002. select * from author. insert into author values (3. insert into odetails values (1.101.1001.'aus').'ame').5).1.'lib2'. insert into catalog values (112.115. insert into catalog values (113. insert into category values (1005. AID NAME CITY COUNTRY ---------. bid references catalog. insert into odetails values (2.'mik'.'computer').'ame').'lib6'.'anan'. insert into publisher values (102. insert into odetails values (4. insert into publisher values (103. insert into catalog values (111.2.'lib1'.'electronics').'tri'. insert into catalog values (116.800).2002.'lib8'.1005.113.2). insert into category values (1002.500).3).114.2007. insert into author values (2.'euro').'anan'.111.'maths').450).111. insert into odetails values (2.2). insert into author values (4.600).

ONO BID QTY ---------. PID NAME CITY COUNTRY ---------.country from author where aid in (select aid from catalog where year>2000 and price>(select avg(price) from catalog) .---------1 111 2 2 112 3 3 111 5 4 113 1 5 114 2 6 115 1 1 114 2 2 113 2 iii.city.--------------101 pearson bang ind 102 tata mumbai aus 103 sapna che euro 104 abc tri ame 105 xyz anan ind select * from category.---------.--------.--------------------1001 computer 1002 electronics 1003 maths 1004 science 1005 electrical select * from catalog. Give the detail of the author who have 2 or more books in the catalog and the price of the book is greater than the average price of the book in the catalog and the year of publication after 2000 select name.--------------.Anjuman Engineering College.-------.-----------. Bhatkal 17 Database Applications Laboratory select * from publisher. CID DESCRIPTION ---------.---------.--------------.-------. BID TITLE AID PID CID YEAR PRICE ------.---------111 lib1 1 101 1001 2002 500 112 lib2 2 102 1002 2000 800 113 lib3 3 103 1003 2003 200 114 lib4 4 104 1001 2006 350 115 lib5 5 105 1004 2007 100 116 lib6 2 103 1005 2007 600 117 lib7 2 105 1002 2007 450 118 lib8 1 101 1001 2002 500 select * from odetails.

--------------1 mik v. Bhatkal 18 Database Applications Laboratory group by aid having count(*)>1).-------.--------------.Anjuman Engineering College.bid=(select bid from odetails group by bid having sum(qty)=(select max(sum(qty)) from odetails group by bid)).---------111 lib1 1 101 1001 2002 500 112 lib2 2 102 1002 2000 800 113 lib3 3 103 1003 2003 200 114 lib4 4 104 1001 2006 385 115 lib5 5 105 1004 2007 100 116 lib6 2 103 1005 2007 600 117 lib7 2 105 1002 2007 450 118 lib8 1 101 1001 2002 500 .aid and c.1*price where pid in (select pid from publisher where name='abc'). Find the author of the book which has maximum sales select a.aid=c.aid. AID NAME ---------.--------.---------. NAME CITY COUNTRY ----------. BID TITLE AID PID CID YEAR PRICE ------.-----------. Demonstrate how to increase the price of books published by a specific publisher by 10% update catalog set price=1. name from author a. catalog c where a.-------.--------------mik bang ind muj bang ind iv. select * from catalog.

Consider the following database for a banking enterprise BRANCH (branch_name: string. create table depositor ( cname varchar(10). Find all the customers who atleast two accounts at the MAIN branch. vii) Create suitable front end for querying and displaying the results. create table branch ( bname varchar(10) primary key. assets real ). cstreet varchar(10) not null.accno). Find all the customers who have an account at all branches located in a specific city. bname varchar(10). vi) Generation of suitable reports. primary key(cname. accno int. . Demonstrate how you delete all account tuples at every branch located in a specific city. amount: real) BORROWER (customer_name: string. Enter atleast five tuples for each relation. foreign key(bname) references branch(bname) ). loan_number: int) i) ii) iii) iv) v) Create the above tables by properly specifying the primary keys and the foreign keys. balance: real) CUSTOMER (customer_name: string. Bhatkal 19 Database Applications Laboratory 5. city varchar(10) not null ). branch_city: string. branch_name: string. create table cust ( cname varchar(10) primary key. city:string) DEPOSITOR (customer_name: string. assets: real) ACCOUNT (accno: int. accno: int) LOAN (loan_number: int. balance real. customer_street: string. city varchar(10). foreign key(accno) references account(accno) on delete cascade. foreign key(cname) references cust(cname) on delete cascade ).Anjuman Engineering College. branch_name: string. create table account ( accno int primary key.

Bhatkal 20 Database Applications Laboratory create table loan ( lno int primary key.'xyz'. insert into cust values('prad'.600000).'ef'. primary key(cname. insert into depositor values('prad'. insert into depositor values('muj'. insert into depositor values('mik'. insert into branch values('abn'. lno int.25000). insert into insert into insert into insert into insert into insert into account values(1. foreign key(bname) references branch(bname) on delete cascade ). insert into cust values('now'.10000). account values(5. insert into loan values(1.'abc'.'hyd').'bang'.lno). foreign key(lno) references loan(lno) on delete cascade ).'def'. insert into cust values('muj'.10000).'def'.Anjuman Engineering College.'mum'.20000). insert into loan values(4.3). create table borrower ( cname varchar(10).'bang'). insert into depositor values('mik'. insert into loan values(3.50000). insert into depositor values('waj'. account values(6.1). .2).5000).6).12000).3500).'op'. insert into loan values(2.'mno'.'cd'. insert into cust values('waj'. insert into loan values(5.'bang'. insert into branch values('xyz'.1500). insert into branch values('mno'.'ab'.'che'.'abc'. insert into cust values('mik'. insert into depositor values('muj'. amt real.330000).555555).'mum').'def'. foreign key(cname) references cust(cname) on delete cascade.'hyd'.'lm'.'abn'.2000000).'abn'. bname varchar(10) not null. account values(2.'bang'). insert into cust values('maj'.5). account values(4. insert into depositor values('maj'.9999999).'xyz'.1000).4). insert into branch values('def'.'mno'.3). account values(3.'che').1200000).'xy'. insert into branch values('abc'.'del').

insert into borrower values('muj'. insert into borrower values('waj'. BNAME CITY ------------------abc bang def che abn mum xyz hyd mno bang ASSETS ---------1200000 2000000 330000 555555 9999999 select *from account. select *from branch.3).2). CNAME CSTREET --------------------mik ab muj cd maj ef waj xy prad lm now op select *from depositor.4). insert into borrower values('prad'.1). ACCNO BNAME BALANCE ---------------------------1 abc 25000 2 def 12000 3 def 1000 4 abn 10000 5 mno 600000 6 xyz 50000 select *from cust.Anjuman Engineering College. CNAME ACCNO ---------.-----------mik 2 muj 1 muj 5 prad 4 maj 3 waj 6 mik 3 CITY ---------bang bang che del mum hyd . insert into borrower values('maj'.5). Bhatkal 21 Database Applications Laboratory insert into borrower values('mik'.

Bhatkal 22 Database Applications Laboratory select *from loan. Find all the customers who atleast two accounts at the MAIN branch.---------mik 2 muj 1 prad 3 maj 4 waj 5 iii.cname=c.-----------.accno and d.accno=a.---------1 abc 5000 2 def 1500 3 abn 10000 4 xyz 3500 5 mno 20000 select *from borrower. select cname from account a. LNO BNAME AMT ---------. Find all the customers who have an account at all branches located in a specific city select cname from cust c where not exists (select bname from branch where city='bang' minus select bname from depositor d.--------------1 abc 25000 4 abn 10000 5 mno 600000 6 xyz 50000 ************** . 2 rows deleted.accno=d. Demonstrate how you delete all account tuples at every branch located in a specific city. delete from account where bname in (select bname from branch where city='che').account a where d. CNAME ---------mik iv.accno and bname='def' group by cname having count(*)>1.Anjuman Engineering College.cname) and exists (select bname from branch where city='bang'). ACCNO BNAME BALANCE ----------. select *from account. CNAME LNO ------------. CNAME -----------muj v.-----------.depositor d where a.

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.