Dbms Lab External © MR - Stark
Dbms Lab External © MR - Stark
1. Suppose a movie_studio has several film crews. The crews might be designated by a
given studio as crew1, crew2, and so on. However, other studios might use the same
designations for crews, so the attribute crew_number is not a key for crews.
Movie_studio holds the information like name, branch and several locations. Each
crew holds information like sector, and strength.
a. Establish the database by normalising up to 3NF and considering all schema level
constraints.
b. Write SQL insertion query to insert few tuples to all the relations.
c. List all movies studios which are not used a single crews.
d. Retrieve the movie_studio which uses highest strength crew.
e. Write a before insert trigger to check maximum number of crews to any studio is
limited to 5.
f. Write a procedure retrieve all crews used by specific studio.
a)
name varchar(10),
branch varchar(10),
);
crew_no number(10),
name varchar(10),
strength number(10),
sector varchar(20),
);
name varchar(10),
location varchar(20),
);
c)
select name
from movie
from crew);
d)
select name
from crew
from crew);
select name
from crew c
e)
declare
cnt number;
begin
where name=:NEW.name;
if(cnt>5) then
end if;
end;
f)
is
X crew%rowtype;
begin
for X in c loop
end loop;
end;
2. The production company is organised into different studios. We store each studio’s
name, branch and location; every studio must own at least one movie. We store each
movie’s title, censor_number and year of production. star may act in any number of
movies and we store each actors name and address.
a. Establish the database by normalising up to 3NF and considering all schema level
constraints.
b. Write SQL insertion query to insert few tuples to all the relations.
c. List all the studios of the movie “xyz”.
d. List all the actors, acted in a movie “xyz”.
e. Write a procedure to list all movies produced during the specific year.
f. Write a deletion trigger, does not allow to deleting the current year movies.
a)
st_name varchar(20),
branch varchar(20),
location varchar(20),
sensor_no varchar(20),
title varchar(20),
year number(5),
);
star_name varchar(20),
address varchar(20),
);
st_name varchar(20),
sensor_no varchar(20),
);
star_name varchar(20),
sensor_no varchar(20),
);
b)
c)
select s.st_name
d)
select s.star_name
e)
is
x movie1.title%type;
from movie1 c
where c.year=s;
begin
for x in c loop
sys.dbms_output.put_line(x.title);
end loop;
end;
f)
declare
cur number;
begin
from dual;
if(:OLD.year=cur) then
raise_application_error(-20009,'Cannot delete');
end if;
end;
3. The production company is organised into different studios. We store each studio’s
name, branch and location; a studio own any number of cartoon-serials. We store each
cartoon-serials’s title, censor_number and year of production. star may do voices in
any number of cartoon-serials and we store each actors name and address.
a. Establish the database by normalising up to 3NF and considering all schema level
constraints.
b. Write SQL insertion query to insert few tuples to all the relations.
c. Find total no. of actors, do voiced in a cartoon-serials “xyz”.
d. Retrieve name of studio, location and cartoon-serials title in which star “abc’ is
voiced.
e. Write a procedure to list all cartoon-serials produced during the specific year.
f. Write a deletion trigger, does not allow to deleting the current year cartoon-serials.
a)
st_name varchar(20),
branch varchar(20),
location varchar(20),
);
sensor_no varchar(20),
title varchar(20),
year number(5),
);
star_name varchar(20),
address varchar(20),
);
st_name varchar(20),
sensor_no varchar(20),
);
star_name varchar(20),
sensor_no varchar(20),
);
b)
c)
select count(*)
d)
select s.st_name,s.location,c.title
e)
is
x cartoon.title%type;
from cartoon c
where c.year=s;
begin
for x in c loop
sys.dbms_output.put_line(x.title);
end loop;
end;
f)
declare
cur number;
begin
from dual;
if(:OLD.year=cur) then
raise_application_error(-20019,'Cannot delete');
end if;
end;
4. Car marketing company wants keep track of marketed cars and their owner. Each car
must be associated with a single owner and owner may have any number of cars. We
store car’s registration number, model & colour and owner’s name, address & SSN.
We also store date of purchase of each car.
a. Establish the database by normalising up to 3NF and considering all schema level
constraints.
b. Write SQL insertion query to insert few tuples to all the relations.
c. Find a person who owns highest number of cars.
d. Retrieve persons and cars information purchased on day dd/mm/yyyy.
e. Write a procedure to list all cars and owner information purchased during the
specific year.
f. Write a insertion trigger to check date of purchase must be less than current date
(must use system date).
a)
ssn number(10),
name varchar(20),
address varchar(20),
);
rgno number(10),
model varchar(10),
color varchar(10),
ssn number(10),
dop date,
);
b)
c)
select o.name,c.ssn,count(c.ssn)
where o.ssn=c.ssn
group by o.name,c.ssn
from car2 m
group by (m.ssn));
d)
select o.ssn,o.name,c.rgno,c.model
e)
is
X owner2%rowtype;
X1 car2%rowtype;
cursor c is select o.* from owner2 o,car2 c1 where c1.ssn=o.ssn and dop=pur_date;
cursor f is select c1.* from owner2 o,car2 c1 where c1.ssn=o.ssn and dop=pur_date;
begin
sys.dbms_output.put_line('OWNER DETAILS');
for X in c loop
end loop;
sys.dbms_output.put_line('CAR DETAILS');
for X1 in f loop
end loop;
end;
f)
declare
cur date;
begin
if(cur<:NEW.dop) then
raise_application_error(-20009,'incorrect date');
end if;
end;
/
5. Puppy pet shop wants to keep track of dogs and their owners. The person can buy
maximum three pet dogs. we store person’s name, SSN and address and dog’s name,
date of purchase and sex. The owner of the pet dogs will be identified by SSN since
the dog’s names are not distinct.
a. Establish the database by normalising up to 3NF and considering all schema level
constraints.
b. Write SQL insertion query to insert few tuples to all the relations.
c. List all pets owned by a person “abhiman”.
d. List all persons who are not owned a single pet.
e. Write a trigger to check the constraints that person can buy maximum three pet
dogs.
f. Write a procedure to list all dogs and owner details purchased on the specific date.
a)
oname varchar(10),
ssn number(10),
address varchar(30),
ssn number(10),
dname varchar(10),
sex varchar(5),
dop date,
b)
to check trigger
c)
select dname,sex,dop
d)select o.oname
from ownerofdog o
from doggg d
where o.ssn=d.ssn);
e)
declare
cnt number;
begin
if(cnt>3) then
end if;
end;
f)
is
X1 dog%rowtype;
X owner%rowtype;
begin
dbms_output.put_line('OWNER DETAILS');
for X in c loop
end loop;
dbms_output.put_line('DOG DETAILS');
for X1 in f loop
end loop;
end;
6. Education institute is managing the online course enrolment system. Students can
enrol maximum of six courses of their choice and a maximum student to be enrolled
to any course is 60. We store student details like name, USN, semester and several
addresses, course details like unique title, unique id and credits.
a. Establish the database by normalising up to 3NF and considering all schema level
constraints.
b. Write SQL insertion query to insert few tuples to all the relations.
c. Find number of students enrolled for the course ‘DBMS’.
d. Retrieve student names that are enrolled for data structure course but not enrolled
for logic design.
e. Write a trigger to establish the constraint that the students can enrol maximum of
six course of their choice.
f. Write a procedure to list all the courses enrolled by the seventh semester students.
a)
usn number(10),
name varchar(20),
sem varchar(10),
);
cid number(10),
credits number(10),
);
usn number(10),
cid number(10),
);
b)
c)
select count(s.usn)
d)
select s.name
minus
select s.name
e)
declare
var1 number;
begin
if(var1>6)
then
raise_application_error(-20009,'limit reached');
end if;
end;
f)
is
X course%rowtype;
cursor c is select c1.title from course c1, stud1 s,enroll e where s.usn=e.usn and
c1.cid=e,cid ans s.sem='7';
begin
for X in c loop
sys.dbms_output.put_line(c.name);
end loop;
end;
7. The commercial bank wants to keep track of the customer’s account information.
Each customer may have any number of accounts and account can be shared by any
number of customers. The system will keep track of the date of last transaction. We
store the following details:
i. account: unique account number, type and balance.
ii. customer: unique customer id, name and several addresses
composed of street, city and state.
a. Establish the database by normalising up to 3NF and considering all schema level
constraints.
b. Write SQL insertion query to insert few tuples to all the relations.
c. Add 3% interest to the customer who have less than 10000 balances and 6%
interest to remaining customers.
d. List joint accounts involving more than three customers.
e. Write a insertion trigger to allow only current date for date of last transaction
field.
f. Write a procedure to find the customer who has highest number of accounts, the
customer who has lowest balance, the customer who involved in most of joint
accounts.
c_id varchar(10),
name varchar(10),
);
acc_no number(10),
type varchar(10),
balance number(100000),
);
c_id varchar(10),
acc_no number(10),
last_tr date,
);
c_id varchar(10),
street varchar(20),
city varchar(20),
state varchar(20),
);
b)
c)
update account
set balance=case
else balance*1.06
end;
d)
select max(distinct(count(acc_no)))
from account
group by acc_no;
e)
declare
cur_date date;
begin
if((:NEW.last_tr-cur_date)<=0) then
raise_application_error(-20006,'INVALID DATE');
end if;
end;
f)
is
X customer%rowtype;
cursor c is
select ca.c_id,c1.name,count(ca.acc_no)
where c1.c_id=ca.c_id
group by ca_cid,c1.name
from cust_acc ca
group by ca.c_id;
cursor f is
begin
for X in c loop
sys.dbms_output.put_line(X.c_id||' '||X.name);
end loop;
for X in f loop
sys.dbms_output.put_line(X.c_id||' '||X.name);
end loop;
end;
8. The commercial bank wants to keep track of the customer’s loan information. Each
customer can take any number of loans from the bank and loan will not be shared.
The system will keep track of the date of last transaction. We store the following
details:
i. loan: unique loan number, type and amount.
ii. customer: unique customer id, name, annual income and several addresses
composed of street, city and state.
a. Establish the database by normalising up to 3NF and considering all schema level
constraints.
b. Write SQL insertion query to insert few tuples to all the relations.
c. Add 12% interest to the customer who have less than 50000 amount and 14%
interest to remaining customers.
d. Retrieve the customers who have single loan in a bank.
e. Write a insertion trigger to loan, that does not allow if the loan amount is more
than two times of customers annual income.
f. Write a procedure to retrieve all the loans of a specific customer.
c)
update loans
set amount=case
else balance*1.14
end;
d)
select c.cname,l.cid,count(l.lno)
where c.cid=l.cid
group by c.cname,l.cid
having count(lno=1);
e)
begin
raise_application_error(-20009,'LIMIT EXCEEDED');
end if;
end;
f)
is
X loans%rowtype;
cursor c is select l.* from customer c1, loans l where c1.cname=name and
l.cid=c1.cid;
begin
sys.dbms_output.put_line('LOAN DETAILS');
for X in c loop
end loop;
end;
9. The xyz book shop wants keep track of orders of the book. The book is composed of
unique id, title, year of publication, single author and single publisher. Each order will
be uniquely identified by order-id and may have any number of books. We keep track
of quantity of each book ordered. We store the following details:
i. author: unique author-id, name, city, country.
ii. Publisher: unique publisher-id, name, city, country.
orderid varchar(10),
);
bid varchar(10),
btitle varchar(10),
byop number,
aid varchar(10),
pid varchar(10),
);
aid varchar(10),
aname varchar(10),
acity varchar(10),
acountry varchar(10),
);
pid varchar(10),
pname varchar(10),
pcity varchar(10),
pcountry varchar(10),
);
orderid varchar(10),
bid varchar(10),
);
b)
c)
select a.aname,b.aid,count(b.bid)
where a.aid=b.aid
group by a.aname,b.aid
from book b
group by b.aid);
d)
select btitle
from book
e)
declare
cur number;
begin
from dual;
if(:NEW.byop!=cur) then
raise_application_error(-20019,'Cannot insert');
end if;
end;
f)
is
X book%rowtype;
cursor c is select b.* from book b,author a where a.aname=name and b.byop=year and
a.aid=b.aid;
begin
sys.dbms_output.put_line('BOOK DETAILS');
for X in c loop
end loop;
end;
Disclaimer