5th Sem Dbms Lab Programs
5th Sem Dbms Lab Programs
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
5 d2 4 1000
2 a2 5 1200
3 b2 6 10000
2 a1 6 5000
iii.a Update the damage amount for the car with a specific regno in accident with report
number 12 to 25000
iv. Find the total number of people who owned cars that were involved in accidents in 2006
select count(distinct p.driverid) from accident a,owns o,participated p
where date1 like '%06' and a.reportno=p.reportno
and p.regno=o.regno and o.driverid=p.driverid;
COUNT(DISTINCTP.DRIVERID)
---------------------------------------------
4
v. Find the number of accidents in which cars belonging to a specific model were involved.
select count(*) from car c,participated p where model='porsche' and c.regno=p.regno;
COUNT(*)
--------------
2
Anjuman Engineering College, Bhatkal 6
Database Applications Laboratory
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) Produce a listing: CUSTNAME, NO_OF_ORDERS, AVG_ORDER_AMT, 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.
iv) List the Order# for the orders that were shipped from all the 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) Generation of suitable reports.
vii) Create a suitable front end for querying and displaying the results.
select c.cname,count(q.qty),avg(oamt)
from customer c, order1 o, oitem q
where q.ono=o.ono and c.cno=o.cno
group by cname;
iv. List the Order# for the orders that were shipped from all the 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
delete from item where ino=5;
1 row deleted
3. Consider the following database of student enrollement in courses and books adopted for
each course .
i) Create the above tables by properly specifying the primary keys and the foreign key .
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.
iv) Produce a list of text books( include course # ,book_isbn,book-title) in the
alphabetical order for courses offered by the cs department that use more than 2 books.
v) List any department that has all its adopted books published by specific publisher.
vi) Generation of suitable reports.
vii) Create suitable front end for querying and display the results
iii.Demonstrate how you add a new text book to the database and make this book be
adopted by some department.
insert into text values(106,'JAVA','pearson','Avril');
insert into bad values(2,7,106);
SELECT s.cno,t.title,b.isbn
FROM course s,bad b,text t
where s.cno=b.cno
AND b.isbn=t.isbn
AND s.dept='computer'
AND b.cno in (select b.cno
from bad b,course s
where b.cno=s.cno
group by b.cno
having count(*)>2)
order by t.title;
v. List any department that has all its adopted books published by specific publisher.
select s.dept, t.publisher
from course s, bad b, text t
where s.cno=b.cno
and t.isbn=b.isbn
and publisher='lpe';
DEPT PUBLISHER
------------- --------------------
computer lpe
infosci lpe
Anjuman Engineering College, Bhatkal 15
Database Applications Laboratory
4. Consider the following relations for the details maintained by a book dealer.
iii. 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,city,country
from author
where aid in (select aid from catalog where year>2000 and price>(select avg(price) from
catalog)
Anjuman Engineering College, Bhatkal 18
Database Applications Laboratory
iv. Find the author of the book which has maximum sales
select a.aid, name from author a, catalog c
where a.aid=c.aid and c.bid=(select bid from odetails group by bid having
sum(qty)=(select max(sum(qty)) from odetails group by bid));
AID NAME
---------- ---------------
1 mik
i) Create the above tables by properly specifying the primary keys and the foreign keys.
ii) Enter atleast five tuples for each relation.
iii) Find all the customers who atleast two accounts at the MAIN branch.
iv) Find all the customers who have an account at all branches located in a specific city.
v) Demonstrate how you delete all account tuples at every branch located in a specific
city.
vi) Generation of suitable reports.
vii) Create suitable front end for querying and displaying the results.
iii. Find all the customers who atleast two accounts at the MAIN branch.
select cname from account a,depositor d where a.accno=d.accno and bname='def' group by
cname having count(*)>1;
CNAME
----------
mik
iv. 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,account a
where d.accno=a.accno and d.cname=c.cname)
and exists
(select bname from branch where city='bang');
CNAME
------------
muj
v. 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');
2 rows deleted.
**************