You are on page 1of 3

drop table student cascade constraints;

drop table course cascade constraints;


drop table enroll cascade constraints;
drop table text cascade constraints;
drop table bad cascade constraints;

create table student


(
regno varchar(5) primary key,
name varchar(10) not null,
major varchar(10) not null,
bdate date not null
);
create table course
(
cno int primary key,
cname varchar(10) not null,
dept varchar(10) not null
);
create table enroll
(
regno varchar(5),
cno int,
sem int,
marks int not null,
primary key(regno,cno),
foreign key(regno) references student(regno) on delete cascade,
foreign key(cno) references course(cno) on delete cascade
);
create table text
(
isbn int primary key,
title varchar(15) not null,
publisher varchar(10) not null,
author varchar(10) not null
);
create table bad
(
cno int,
sem int,
isbn int not null,
primary key(cno,sem),
foreign key(cno) references course(cno) on delete cascade,
foreign key(isbn) references text(isbn) on delete cascade
);
student
insert into student values('cs42','mikhil','cse','17-dec-1986');
insert into student values('cs48','mujeeb','cse','02-sep-1986');
insert into student values('ec26','pradeep','cse','16-aug-1987');
insert into student values('ee37','majid','ise','28-may-1986');
insert into student values('is48','wajid','ise','28-may-1986');
course
insert into course values(1,'.net','computer');
insert into course values(2,'j2ee','computer');
insert into course values(3,'mis','infosci');
insert into course values(4,'fs','infosci');
insert into course values(5,'oracle','computer');

enroll
insert into enroll values('cs42',1,6,98);
insert into enroll values('cs48',2,6,97);
insert into enroll values('ec26',5,5,50);
insert into enroll values('is48',3,7,90);
insert into enroll values('ee37',4,4,80);
insert into enroll values('cs48',1,6,35);
text
insert into text values(101,'let us c','lpe','fahad');
insert into text values(102,'c++','abc','mujeeb');
insert into text values(103,'oracle','def','othman');
insert into text values(104,'.net','abc','naushad');
insert into text values(105,'j2ee','pearson','mikhil');
bad
insert into bad values(1,6,101);
insert into bad values(2,6,103);
insert into bad values(3,5,102);
insert into bad values(4,4,104);
insert into bad values(5,7,105);
insert into bad values(5,3,104);
insert into bad values(5,4,103);

3.Demonstrate how you add a new text book to the database and make this book be
adopted by some department.
insert into text values(106,'JAVA','pearson','Avril');
insert into bad values(2,7,106);
4. 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.
SELECT s.cno,t.title,b.isbn
FROM course s,bad b,text t
where s.cno=b.cno
AND b.isbn=t.isbn
AND s.dept='computer'
AND b.cno in (select b.cno
from bad b,course s
where b.cno=s.cno
group by b.cno
having count(*)>2)
order by t.title;

5.. List any department that has all its adopted books published by specific pub
lisher.
select distinct C.dept
from course C, bad A, text T
where C.cno =A.cno and A.isbn=T.isbn and not exists
((select Y.isbn
from course X,bad Y
where X.cno =Y.cno and X.dept=C.dept)
MINUS
(select isbn from text where publisher='abc'));

drop table student cascade constraints;


drop table course cascade constraints;
drop table enroll cascade constraints;
drop table text cascade constraints;
drop table bad cascade constraints;

You might also like