Dbms Lab Exp1
Dbms Lab Exp1
Dbms Lab Exp1
Program -1
Aim: Demonstrating creation of tables, applying the view concepts on the tables.
Program: Consider the following schema for a Library Database:
BOOK(Book_id, Title, Publisher_Name, Pub_Year)
BOOK_AUTHORS(Book_id, Author_Name)
PUBLISHER(Name, Address, Phone)
BOOK_COPIES(Book_id, Programme_id, No-of_Copies)
BOOK_LENDING(Book_id, Programme_id, Card_No, Date_Out, Due_Date)
LIBRARY_PROGRAMME(Programme_id, Programme_Name, Address)
Write SQL queries to
i. Retrieve details of all books in the library – id, title, name of PUBLISHER, authors,
number of copies in each branch, etc.
ii. Get the particulars of borrowers who have borrowed more than 3 books, but from Jan
2017 to Jun 2017.
iii. Delete a book in BOOK table. Update the contents of other tables to reflect this data
manipulation operation.
iv. Partition the BOOK table based on year of publication. Demonstrate its working with
a simple query.
v. Create a view of all books and its number of copies that are currently available in the
Library.
Schema Diagram:
primary key(programme_id) );
Output
Output
(i)Write SQL queries to retrieve details of all books in the library – id, title, name of
PUBLISHER, authors, number of copies in each branch, etc.
Query: select b.book_id, b.title,b.publisher_name,a.author_name,c.no_of_copies,
c.progarmme_id from BOOK b, BOOK_AUTHORS a, BOOK_COPIES c
where b.book_id=a.book_id and b.book_id=c.book_id;
Output
(ii) Write SQL queries to get the particulars of borrowers who have borrowed more than 3
books, but from Jan 2017 to Jun 2017.
Query: select card_no from BOOK_LENDING
where date_out between '01-jan-17' and '30-jun- 17'
group by card_no
having count(*)>3;
Output
(iii) Write SQL queries to delete a book in BOOK table. Update the contents of other tables
to reflect this data manipulation operation.
Query: delete from BOOK where book_id=3;
Output
Output
(v) Write SQL queries to create a view of all books and its number of copies that are
currently available in the Library.
Query: create view no_of_copies as( select book_id,sum(no_of_copies) as copies from
BOOK_COPIES group by book_id);
Output
select *from no_of_copies;