Sie sind auf Seite 1von 4

thr

EXPERIMENT 6
AIM: To construct a video library database and write queries
according to the given question.
Question: Consider the following database schema for video library scenario:-
CUSTOMER (cust_no, cust_name)
MEMBERSHIP (mem_no, cust_no)
CASSETTE (cass_no, cass_name , language)
ISS_REC (iss_no, iss_date, mem_no, cass_no)

The primary keys are underlined.
For the above schema, perform the following:
(1) Create the tables with the appropriate integrity constraints.
(2) Insert around 10 records in each of the tables.
(3) List all the customer names with their membership numbers.
(4) List all the issues for the current date with the customer names and cassette names.
(5) List the details of the customer who has borrowed the cassette whose title is The
Legend.
(6) Give a count of how many cassettes have been borrowed by each customer.
(7) Give a list of book which has been taken by the student with mem_no as 5.
(8) List the cassettes issues for today.
Source Code

(1) & (2) -

create table customer( cust_no integer not null ,
cust_name varchar(20) ,primary key(cust_no));

insert into customer values (1,'Ajitesh');
insert into customer values (2,'Aman');
insert into customer values (3,'Bhavik');
insert into customer values (4,'Chetan');
insert into customer values (5,'Dhruv');
thr
insert into customer values (6,'Harsh');
insert into customer values (7,'Jayesh');
insert into customer values (8,'Karthik');
insert into customer values (9,'Prakhar');
insert into customer values (10,'Raj');

create table membership ( mem_no integer not null ,
cust_no integer not null ,
primary key(mem_no) ,
foreign key(cust_no) references customer(cust_no));

insert into membership values(1001,1);
insert into membership values(1002,2);
insert into membership values(1003,3);
insert into membership values(1004,4);
insert into membership values(1005,5);
insert into membership values(1006,6);
insert into membership values(1007,7);
insert into membership values(1008,8);
insert into membership values(1009,9);
insert into membership values(1010,10);

create table cassette ( cass_no integer not null ,cass_name
varchar(20) ,language varchar(20) ,
primary key(cass_no));

insert into cassette values (2001,'Dark Knight' ,'English');
insert into cassette values (3001,'Chak De India, 'Hindi');
insert into cassette values (2002,'Godfather' ,'English');
insert into cassette values (2003,'Inception' ,'English');
insert into cassette values (3002,'Kahani' ,'Hindi');
insert into cassette values (3003,'Lagaan' ,'Hindi');
insert into cassette values (2004,'Fight Club' ,'English');
insert into cassette values (2005,'The Matrix' ,'English');
insert into cassette values (3004,'Jab We Met' ,'Hindi');
insert into cassette values (2006,'The Legend' ,'English');

create table iss_rec ( iss_no integer not null ,
iss_date date , mem_no integer not null ,
cass_no integer not null ,
primary key(iss_no) ,
foreign key(mem_no) references membership(mem_no),
foreign key(cass_no) references cassette (cass_no));

insert into iss_rec values (101,'15-MAR-2013',1001,2002);
insert into iss_rec values (102,'30-MAR-2013',1001,3003);
insert into iss_rec values (103,'30-MAR-2013',1002,2001);
thr
insert into iss_rec values (104,'28-FEB-2013',1003,2006);
insert into iss_rec values (105,'07-MAR-2013',1004,2005);
insert into iss_rec values (106,'30-MAR-2013',1004,3001);
insert into iss_rec values (107,'25-MAR-2013',1004,2003);
insert into iss_rec values (108,'20-MAR-2013',1005,2004);
insert into iss_rec values (109,'17-MAR-2013',1006,3004);
insert into iss_rec values (110,'30-MAR-2013',1006,2002);
insert into iss_rec values (111,'25-FEB-2013',1007,3002);
insert into iss_rec values (112,'16-MAR-2013',1008,2002);
insert into iss_rec values (113,'30-MAR-2013',1005,2005);
insert into iss_rec values (114,'25-MAR-2013',1008,2004);
insert into iss_rec values (115,'21-MAR-2013',1009,3001);
insert into iss_rec values (116,'30-MAR-2013',1010,2003);

(3)

select c.cust_name , m.mem_no
from customer c , membership m
where c.cust_no=m.cust_no;


(4)

select i.iss_no,i.iss_date,c.cust_name,cass.cass_name
from iss_rec i , membership m , customer c , cassette cass
where trunc(i.iss_date) = trunc(sysdate) and
i.mem_no = m.mem_no and m.cust_no=c.cust_no
and i.cass_no=cass.cass_no;







thr
(5)
select m.mem_no,c.cust_no,c.cust_name
from iss_rec i , membership m , customer c , cassette cass
where cass.cass_name='The Legend' and
cass.cass_no = i.cass_no and i.mem_no =
m.mem_no and m.cust_no=c.cust_no;


(6)

select c.cust_name, count(i.mem_no) as 'No of cassettes
issued'
from iss_rec i , membership m , customer c
where i.mem_no = m.mem_no and m.cust_no = c.cust_no
group by c.cust_name


(7)

select cass.cass_name
from iss_rec i , membership m , cassette cass
where m.mem_no=1005 and m.mem_no=i.mem_no and
i.cass_no=cass.cass_no;


(8)

select cass.cass_name as 'Cassettes issued today'
from iss_rec i , cassette cass
where trunc(i.iss_date) = trunc(sysdate)
and .cass_no=cass.cass_no;