DBMS LAB MANUAL FINAL (AutoRecovered)
DBMS LAB MANUAL FINAL (AutoRecovered)
TABLE OF CONTENTS
1 STUDENT DB
2 LIBRARY DB
3 SALARY DB
4 INSURANCE DB
5 STUDENT ENROLL DB
6 BOOK DEALER DB
7 BANK DB
8 ORDER PROCESSING DB
1. The STUDENT detail databases has a table with the following attributes. The
primary
keys are underlined. STUDENT(regno: int, name: string, dob: date, marks: int)
i) Create the above table.
ii) Remove the existing attributes from the table.
iii) Change the date type of regno from integer to string.
iv) Add a new attribute phoneno to the existing table.
v) Enter five tuples into the table.
vi) Display all the tuples in student table.
Solutions:
Create table student(regno int primary key , name varchar(20), dob date, marks
number(10))
Solutions:
SALARY DATABASE
3. The SALARY database of an organization has a table with the following
attributes.
vi) Find the least and highest salaries that an employee draws.
Solutions:
Consider the insurance database given below. The primary keys are
underlined and the data types are specified.
SOLUTIONS
i) Create the above tables by properly specifying the primary keys and the foreign
keys
Create table person(driverid_no varchar(20) primary key,name varchar(20),
address varchar(30))
2. Create table car(regno varchar2(20) primary key, model varchar(20) not
null,year number(5))
d. Find total number of people who owned cars that were involved in accidents in 2002
e. Find the number of accidents in which cars belonging to a specific model were involved
STUDENT ENROLLMENT DATABASE
5. Consider the following database of students enrollment in courses and books adopted
for each course.
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 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-no, book-isbn, book-title) in the
alphabetical order for courses offered by the ‘Compute Science’ department that use
more than two books.
V List any department that has all its adopted books published by a specific publisher.
SOLUTIONS:
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 add a new text book to the database and make this book be
adopted by some department.
1. insert into text values('2222','c++','pradeep','MA Rama');
2. insert into course values(‘6’,’m.tech’,’cs’);
v. List any department that has all its adopted books published by a specific publisher.
select c.department,c.course_name,t.title,t.publisher,b.book_isbn from course c,
text t,book_adaption b
where t.book_isbn=b.book_isbn
and c.course_no=b.course_no and t.publisher='skyward';
BOOK DEALER
6. The following tables are maintained by a book dealer
AUTHOR(author-id: int, name: string, city: string, country: string)
PUBLISHER(publisher-id: int name: string, city: string, country: string)
CATLOG(book-id: int, title : string, author-id: int, publisher-id: int, category: int, year:
int, price: int)
CATEGORY(category-id: int, description: string)
ACCOUNT(accno: int, branch-name: string, balance: real)
DEPOSITOR(customer-name: string, accno: int)
ORDER-DETAILS(order-no: int, book-id: int, quantity: int)
i) Create above tables by properly specifying the primary keys and the foreign keys.
ii) Enter atleast 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 2010.
iv) Find the author of the book which has maximum sales.
v) Demonstrate how to increase price of books published by specific publisher by 10%
Answers
i) Create above tables by properly specifying the primary keys and the foreign keys.
1. create table author (author_id int primary key, name varchar(15), city varchar(10),country
varchar(10));
2. create table publisher(publisher_id int primary key,name varchar(15) not null, city
varchar(15),country varchar(15)) ;
3. create table catalogg(book_id int primary key, title varchar(15),author_id int references
author, publisher_id int references publisher, year number(5),price number(8)) ;
4. create table category(category_id int primary key, description varchar(15));
5. create table order(order_id int primary key,book_id int references catalog, quantity
number(5));
b. Enter atleast five tuples for each relation.
1. insert into author values(1001,’m.a. rama;,’london’,’england’);
`3.
4.
5
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 2010.
select *from author where author_id in (select author_id from catalogg where year>=2010
and price >(select avg(price) from catalogg) group by author_id having count(*)>=2);
iv) Find the author of the book which has maximum sales.
select name from author a,catalogg c where a.author_id=c.author_id and book_id in(select
book_id from order_details where quantity=(select max(quantity) from order_details));
Answers
1.
i. Create table branch (branch_name varchar(20) primary key,branch_city
varchar(20 ) not null ,assets number(10,2))
ii. create table account (accno int primary key , branch_name varchar(15),
balance real , foreign key(branch_name)references branch(branch_name) on
delete cascade);
Account:
Customer1:
insert into customer1 values('arpitha','bnagar street','bangalore');
Loan:
insert into loan values(20,'malleshwaram',20000);
Depositer:
insert into depositer values('arpitha',12);
Borrower:
Insert into borrower values(‘arpitha’,10);
iii) Find all the customers who have atleast two accounts at the main branch.
SQL> create view depacc as(select b.branch_name,a.accno,d.customer_name from
branch b, account a, depositer d where a.accno=d.accno and
a.branch_name=b.branch_name and b.branch_name='jaynagar');
View created.
select customer_name, branch_name,accno from depacc where customer_name in
(select customer_name from depacc group by customer_name having
count(*)>=2);
iv) Find all customer who have an account at all the branches located in a specific
city.
select *from customer1 c where not exists (select branch_name from branch where
branch_city='bangalore' minus select a.branch_name from depositer d, account a
where d.accno=a.accno and d.customer_name=c.customer_name);
b.bcity=’bangalore’ and
d.accno = a.ccno and
a.bname=b.bname
v) Demonstrate how t0 delete all account tuples at every branch located in specific
city.
delete from account where bname in (select bname from branch where
ssbcity=’bangalore’)
8. Consider the following database for ORDER PROCESSING.
CUSTOMER(cust-no: int, cname: string, city: string)
ORDER(orderno: int, odate: date, ord-amt: real)
ORDER_ITEM(orderno: int, itemno:int, qty: int)
ITEM(itemno: int, unitprice: real)
SHIPMENT(orderno: int, warehouseno: int, ship-date: date)
WAREHOUSE(warehouseno: int, city: string)
i) Create the above tables by properly specifying the primary keys and the foreign
keys
ii) Enter atleast five tuples for each relation.
iii) List the order number and ship date for all orders shipped from particular
warehouse
iv) Produce a listing: customer name, no of orders, average order amount
v) List the orders that were not shipped within 30 days of ordering
Answers
i) Create the above tables by properly specifying the primary keys and the foreign
keys
customer2:
create table customer2(cust_no int primary key, cname varchar(30), city varchar(30));
Order2:
create table order2( order_no int primary key, odate date, cust_no references customer2, ord_amt
int);
items1
create table items1( item_no int primary key, unit_price int);
order_item
create table order_item( order_no references order2, item_no references items1,qty int);
warehouse
create table warehouse(warehouse_no int primary key,city varchar(30));
shipment
create table shipment(order_no references order2,warehouse_no references warehouse, ship_date
date);
v) List the orders that were not shipped within 30 days of ordering
select order2.order_no from shipment, order2 where
order2.order_no=shipment.order_no and shipment.ship_date>order2.odate+30;
PART B
TABLE OF CONTENTS
1 RETAILOR DB
2 SET OPERATIONS
3 INNER JOIN
4 CARTESIAN PRODUCT
5 OUTER JOIN
6 EMPLOYEE DB
7 INVENTORY DB
8 DONAR DB