Dbms Lab-1
Dbms Lab-1
Dbms Lab-1
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
SOLUTION:.
i) Create the above tables by properly specifying the primary keys and the foreign
keys
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.
p.reg_no and
2. Consider the following relations for an order processing database application in a company.
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.
Solution:..
i) Create the above tables by properly specifying the primary keys and the
foreign keys.
cname varchar2(30),
city varchar2(30));
odate date,
ord_amt number);
unit_price number);
qty number);
city varchar2(30));
ship_date date);
update orders set ord_amt = (select sum(oi.qty * i.unit_price) from orders_item oi,item I
where oi.order_no = orders.order_no and I.item_no = oi.item_no);
commit;
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 table.
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.
Create suitable front end for querying and display the results
Solution:
i) Create the above tables by properly specifying the primary keys and the foreign key .
name varchar2(30),
major char(1),
bdate date
);
cname varchar2(30),
dept varchar2(30)
);
sem number(1),
marks number(3),
primary key(reg_no,course_no,sem)
);
book_title varchar2(30),
publisher varchar2(30),
author varchar2(30)
);
sem number(1),
);
commit;
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.
count(book_title) >2 ;
v) List any department that has all its adopted books published by specific publisher.
DEPT PUBLISHER
------------------------------ ------------------------------
ca bpb
cse bpb
hr bpb
ise bpb
4. Consider the following relations for the details maintained by a book dealer.
CATALOG (Book-id: int, title: string, author-id: int, Publisher-id: int, Category-id: int, Year: int, Price: 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 is greater than the average 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. Generation of suitable reports.
vii. Create a suitable front end for querying and displaying the results.
Solution:
i) Create the above tables by properly specifying the primary keys and the foreign
keys.
aname varchar2(30),
acity varchar2(30),
acountry varchar2(30)
);
pname varchar2(30),
pcity varchar2(30),
pcountry varchar2(30)
);
description varchar2(30)
);
title varchar2(30),
year number(4),
price number(6,2)
);
qty number(5)
);
commit;
iii) 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.
and
author_id in
(select author_id from catalog group by author_id having count(author_id) > 1);
iv) Find the author of the book which has maximum sales.
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.
Solution:..
i) Create the above tables by properly specifying the primary keys and the foreign keys.
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.