You are on page 1of 6

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

Create table student


(
regno varchar(15) constraint pk_student primary key,
name varchar(15) not null,
major varchar(15) not null,
bdate date not null
);
Insert into student values(‘2sd15cs100’,’Akash’,’CSE’,’12-MAY-1997’);

COURSE (course #:int, cname:string, dept:string)

Create table course


(
course_code int constraint pk_course_id primary key,
cname varchar(15) not null,
dept varchar(30) not null
);

Insert into course values(501,’Operating System’,.’CSE’);

ENROLL ( regno:string, course#:int, sem:int, marks:int)

Create table enroll


(
regno varchar(15) constraint pk_enroll primary key,
course_code int not null,
sem int not null,
constraint fk_enroll foreign key(regno) references student(regno)
);

alter table enroll


add marks int not null;
Alter table enroll
add constraint pk_enroll primary key(regno,course_code);

Insert into enroll values(‘2sd15cs100’,201,5,56);


BOOK _ ADOPTION (course# :int, sem:int, book-ISBN:int)

Create table book_adoption


(
course_code int not null,
sem int not null,
book_isbn int not null,
constraint pk_book_adoption primary key(course_code,book_isbn),
constraint fk_book_adoption_ccode foreign key(course_code) references
course(course_code),
constraint fk_book_adoption_isbn foreign key(book_isbn) references text(book_isbn)
);

insert into book_adoption values(201, 20150101,5);

TEXT (book-ISBN:int, book-title:string, publisher:string, author:string)

Create table text


(
book_isbn int constraint pk_text primary key,
book_title varchar(15) not null,
publisher varchar(15) not null,
author varchar(15) not null,
);

insert into text values(20160102, 'DBMS', 'GK’, 'Navathe');

(iii)  Demonstrate how you add a new text book to the database and make this book be
adopted by some department.
INSERT into text values(105,'Software','Sapna','Naidu');
INSERT into book_adoption values(201,5,105);
(iv)   Produce a list of textbooks (include Course #, Book-ISBN, Book-title) in the
alphabetical order for courses offered by the ‘CS’ department that use more than two
books.
SELECT c.course_code, b.book_isbn, t.book_title
FROM course c, book_adoption b, text t
WHERE cname='CSE' and c.course_code= b.course_code and
b.book_isbn= t.book_isbn and (SELECT count(b1.book_isbn)
FROM book_adoption b1 WHERE c.course_code= b.course_code)>2
ORDER BY t.book_title ASC;

(v)    List any department that has all its adopted books published by a specific publisher.
SELECT distinct c.course_code,c.cname
FROM course c
WHERE c.course_code in (SELECT c.course_code
FROM course c, book_adoption b,text t
where t.publisher='GK')
and c.course_code NOT in
(SELECT c1.course_code
FROM course c1, book_adoption b1,text t1
where t1.publisher!='GK');

(vi) List the regno and name of the students who have enrolled for maximum number of
courses.
SELECT s.regno, s.name, count(e.course_code) as No_Of_Courses
FROM enroll e, student s
WHERE e.regno=s.regno
GROUP by s.regno, s.name
HAVING COUNT(e.course_code)>= all(SELECT COUNT(e1.course_code)
FROM enroll e1, student s1
WHERE e1.regno=s1.regno
GROUP BY e1.course_code);
OR
select * FROM
(
SELECT s.regno, s.name, count(e.course_code) as No_Of_Courses
FROM enroll e, student s
WHERE e.regno=s.regno
GROUP by s.regno, s.name
ORDER BY count(e.course_code) DESC
)
WHERE rownum=1;

(vii) List the text books which have not been adopted by any of the course.
SELECT DISTINCT t.book_isbn
FROM text t
MINUS
SELECT b.book_isbn
FROM book_adoption b, course c
WHERE c.course_code= b.course_code;

(viii) List the book-ISBNs which have been adopted by both Datastructures and
Algorithms.
SELECT b.book_isbn
FROM book_adoption b, course c
WHERE c.course_code= b.course_code and c.cname='Datastuctures'
UNION
SELECT b.book_isbn
FROM book_adoption b, course c
WHERE c.course_code= b.course_code and c.cname='Algorithms';
(ix) List the Book-ISBN and title of book which have been adopted by both Datastructures
and Algorithms.
(SELECT b.book_isbn, t.book_title
FROM book_adoption b, course c, text t
WHERE c.course_code= b.course_code and b.book_isbn= t.book_isbn
and c.cname='ISE')
UNION
(SELECT b.book_isbn, t.book_title
FROM book_adoption b, course c, text t
WHERE c.course_code= b.course_code and b.book_isbn= t.book_isbn
and c.cname='CSE');
(x) List the departments that have all its adopted books published by a specific publisher or
departments that have adopted maximum number of books.
SELECT b.course_code, count(*)
FROM book_adoption b
GROUP BY b.course_code
HAVING count(*)>=all(SELECT COUNT(*)
FROM book_adoption b
GROUP BY b.course_code);

(xi) list the publisher in ascending alphabetical order along with descending alphabetical
order of Book-ISBN,who have published minimum TWO books.
SELECT t.publisher,t.book_isbn, t.book_title

FROM text t

WHERE publisher in(SELECT t1.publisher

FROM text t1 group by t1.publisher

HAVING COUNT(t1.book_isbn)>=2 )

ORDER BY t.publisher asc,t.book_isbn desc;


(xii) List depts which have minimum TEN enrollments for any course that have adopted at least
TWO books.

(xiii) List the courses that have minimum enrollments with maximum books being adopted.

(xiv) List the Course No, Title of the book adopted and Author name if author has written
more than ONE book.

You might also like