0% found this document useful (0 votes)
594 views

DBMS LAB MANUAL FINAL (AutoRecovered)

Uploaded by

shwetha k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
594 views

DBMS LAB MANUAL FINAL (AutoRecovered)

Uploaded by

shwetha k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 46

PART - A

TABLE OF CONTENTS

Expt. Number Name of the Query

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:

i Create the above table.

Create table student(regno int primary key , name varchar(20), dob date, marks
number(10))

ii. Alter table student drop column marks


iii Alter table student modify regno varchar(20)

iv Alter table student add phoneno number(10)

v Insert into student values(regno,name,dob,marks,phoneno)


Vi Select * from student
LIBRARY DATABASE

2. A LIBRARY database has a table with the following attributes.


LIBRARY(bookid:int, title:string, author:string, publication:string, yearpub:int, price:real)
i) Create the above table.
ii) Enter the five tuples into the table
iii) Display all the tuples in library table.
iv) Display the different publishers from the list.
v) Arrange the tuples in the alphabetical order of the book titles.
vi) List the details of all the books whose price ranges between Rs. 100 and Rs. 300 2

Solutions:

a. Create table library (bookid number(10) primary key, title varchar(20),author


varchar(20), publication varchar(20), year number(5),price number(6,2))

2. Insert into library values(&bookid,&title,&author,&publication,&year,&price)


3. Select * from library;

4. Select distinct publication from library

5. Select * from library order by title asc


6. Select * from library where price between 100 and 300

SALARY DATABASE
3. The SALARY database of an organization has a table with the following
attributes.

EMPSALARY(empcod:int, empnamee:string, dob:date, department:string,


salary:real)

i) Create the above table.

ii) Enter the five tuples into the table

iii) Display all the number of employees working in each dapartment.

iv) Find the sum of the salaries of all employees.

v) Find the sum and average of the salaries of employees of a particular


department.

vi) Find the least and highest salaries that an employee draws.

Solutions:

1. Create table salary(empcode number(10) primary key, empname varchar(20),


dob date, dept varchar(15),salary number(10,2))

2. Insert into salary values(&empcode,&empname,&dob,&dept,&salary)


Select *from empsalary;

3. Select dept,count(*) from salary group by dept

4. Select sum(salary) from salary


5. Select sum(salary) , avg(salary) from salary where dept=”computer”

6. Select max(salary) maximum_salary, min(salary) minimum_salary from


empasalary;
INSURANCE DATABSE

Consider the insurance database given below. The primary keys are
underlined and the data types are specified.

PERSON(driver-id-no: string, name: string, address:strong)


CAR(regno: string, model: string, year: int)
ACCIDENT(report-no: int, date: date, location: String)
OWNS(driver-id-no: string, regno: string)
PARTICIPATED(driver-id-no: string, regno: string, report-no: 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 the accident with
report no 12 to 25000.
b) Add a new accident to the database.
iv) Find total number of people who owned cars that were involved in accidents in
2002
v) Find the number of accidents in which cars belonging to a specific model were
involved

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))

3. Create table accident(report_no number(10) primary key, accident_date


date,location varchar (20))

4. Create table owns (driverid_no varchar(20) references person, regno varchar(20)


references car)
5. Create table participated(driver_id varchar2(20) references person,regno
varchar2(20) references card,report_no number(10) references accident
,damage_amount number(10))

ii) Enter atleast five tuples for each relation.

Insert into person values(‘1’,’guru’,’hubli’);


Insert into car values(‘ka01m6699’,’getz’,1998);
Insert into accident values(12,’03-jul-2004’,’richmond town’);
Insert into owns values(‘1’,’ka01m6699’);
Insert into participated values(‘1’,’ka01m6699’,12,25000);
iii) Demonstrate how you
a) Update the damage amount for the car with a specific regno in the accident
with
report no 12 to 25000.
b) Add a new accident to the database.

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.

STUDENT(regno: string, name: string, major: strong, bdate: date)


COURSE(course-no: int cname: string, dept: string)
ENROLL(reg-no: string, course-no: int, sem: int, marks: int)
BOOK-ADOPTION(course-no: 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 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’);

3. insert into book_adaption values(‘6’,’3’,’2222’);


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.
Solution:
1. create view compbooks as
(select c.department,c.course_no,t.title,t.book_isbn from
course c,book_adaption b, text t
where c.course_no=b.course_no
and b.book_isbn=t.book_isbn and department='cs') order by t.title;
2.
select course_no,book_isbn,title from compbooks where department in
(select department from compbooks group by department having count(*)>2);

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));

v) Demonstrate how to increase price of books published by specific publisher by 10%


update catalogg
set price = (price*0.1) + price
where publisher _id = ‘2001’;

select *from catalogg;


7. Consider the following database for BANK.
BRANCH(branch-name: string, branch-city: string, assets: real)
CUSTOMER(customer-name: string, customer-street: string, customer-city: string)
LOAN(loan-no: int, branch-name: string, amount: real)
BORROWER(customer-name: string, loan-no: int)
i) Create the above tables by properly specifying the primary keys and foreign
keys.
ii) Enter atleast five tuples for each relation.
iii) Find all the customers who have atleast two accounts at the main branch.
iv) Find all customer who have an account at all the branches located in a specific
city.
v) Demonstrate how t0 delete all account tuples at every branch located in specific
city.

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);

iii. create table depositor(customer_name varchar(15),accno int,


primary key(customer_name,accno),
foreign key(customer_name)references customer1(customer_name),
foreign key(accno) references account(accno) on delete cascade);
iv. create table customer1 (customer_name varchar(15) primary key,
customer_street varchar(15),customer_city varchar(15))

v. create table loan(loan_no int primary key,branch_name varchar(15), amount


real , foreign key(branch_name)references branch(branch_name));

vi. create table borrower(customer_name varchar(15),loan_no int,


primary key(customer_name,loan_no),
foreign key(customer_name)references customer1(customer_name),
foreign key(loan_no) references loan(loan_no) on delete cascade);
2. Enter 5 tuples into each table
Branch:
SQL> insert into branch values('jaynagar','bangalore',10000)

Account:

SQL> insert into account values(12,'jaynagar',3000);

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);

ii) Enter atleast five tuples for each relation.


insert into customer2 values(10,'ajay','bangalore');
insert into order2 values(12345,'25-mar-2005',10,10);

insert into items1 values(10,100);

insert into order_item values(12345,10,4);


insert into warehouse values(1501,'bangalore');

insert into shipment values(12345,1501,'5-mar-2005');


iii) List the order number and ship date for all orders shipped from particular
warehouse
select order_no,ship_date from shipment where warehouse_no=1501;

iv) Produce a listing: customer name, no of orders, average order amount


select c.cname,count(*) as no_of_order2,avg(ord_amt) as avg_amt from order2
o,customer2 c where c.cust_no=o.cust_no group by(c.cname);

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

Expt. Number Name of the Query

1 RETAILOR DB

2 SET OPERATIONS

3 INNER JOIN

4 CARTESIAN PRODUCT

5 OUTER JOIN

6 EMPLOYEE DB

7 INVENTORY DB

8 DONAR DB

You might also like