DBMS Lab
DBMS Lab
DBMS Lab
sqlplus / as sysdba
Exp no.2 :- Create Schema, insert at least 5 records in each table and add
appropriate constraints for the following Library Database using
ORACLE or MySQL DBMS under LINUX/Windows environment
BOOK (Book_id, Title, Publisher_Name, Pub_Year)
BOOK_AUTHORS (Book_id, Author_Name)
PUBLISHER (Name, Address, Phone)
BOOK_COPIES (Book_id, Branch_id, No-of_Copies)
BOOK_LENDING (Book_id, Br_id, Card_No, Date_Out, Due_Date)
LIBRARY_BRANCH (Branch_id, Branch_Name, Address)
Write SQL queries to
1. Retrieve details of all books in the library – id, title, name of
publisher,authors, number of copies in each branch, etc.
2. Get the particulars of borrowers who have borrowed more than 3
books,but from Jan 2020 to Jun 2022.
3. Delete a book in BOOK table. Update the contents of other tables to
reflect this data manipulation operation.
SELECT
b.book_id,
b.title,
b.publisher_name,
ba.author_name,
p.address AS publisher_address,
p.phone AS publisher_phone,
bc.branch_id,
lb.branch_name,
lb.address AS branch_address,
bc.no_of_copies
FROM
book b
JOIN
book_authors ba ON b.book_id = ba.book_id
JOIN
publisher p ON b.publisher_name = p.name
JOIN
book_copies bc ON b.book_id = bc.book_id
JOIN
library_branch lb ON bc.branch_id = lb.branch_id;
Get Borrowers with More Than 3 Books Borrowed from Jan 2020 to Jun 2022
SELECT
bl.card_no,
COUNT(bl.book_id) AS books_borrowed
FROM
book_lending bl
WHERE
bl.date_out BETWEEN TO_DATE('2020-01-01', 'YYYY-MM-DD') AND
TO_DATE('2022-06-30', 'YYYY-MM-DD')
GROUP BY
bl.card_no
HAVING
COUNT(bl.book_id) > 3;