Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the LIBRARY relational database schema shown below which is used to kee

ID: 3907148 • Letter: C

Question

Consider the LIBRARY relational database schema shown below which is used to keep track of books, borrowers, and book loans. Referential integrity constraints are shown as directed arcs. Write down relational expressions for the following queries:

1. How many copies of the book titled The Lost Tribe are owned by the library branch whose name is ‘Sharpstown’?

2. How many copies of the book titled The Lost Tribe are owned by each library branch?

3. Retrieve the names of all borrowers who do not have any books checked out.

4. For each book that is loaned out from the Sharpstown branch and whose Due_date is today, retrieve the book title, the borrower’s name, and the borrower’s address.

5. For each library branch, retrieve the branch name and the total number of books loaned out from that branch

Explanation / Answer

1. How many copies of the book titled The Lost Tribe are owned by the library branch whose name is ‘Sharpstown’?

select No.Of_Copies
from BOOK_COPIES
inner join Book as BOOK_COPIES.BookId = BOOK.BoodId
inner join LIBRARY_BRANCH as BOOK_COPIES.BranchId = LIBRARY_BRANCH.BranchId
where Title = "The Lost Bribe' and BranchName = 'Sharpstown';

2. How many copies of the book titled The Lost Tribe are owned by each library branch?

select No.Of_Copies, BranchName
from BOOK_COPIES
inner join Book as BOOK_COPIES.BookId = BOOK.BoodId
inner join LIBRARY_BRANCH as BOOK_COPIES.BranchId = LIBRARY_BRANCH.BranchId
where Title = "The Lost Bribe';

3. Retrieve the names of all borrowers who do not have any books checked out.

select Name
from BORROWER
where not exists(select * from BOOK_LOANS
where BOWWOWER.CardNo = BOOK_LOANS.CardNo);

4. For each book that is loaned out from the Sharpstown branch and whose Due_date is today, retrieve the book title, the borrower’s name, and the borrower’s address.

select Title, Name, Address
from BOOK, BORROWER, LIBRARY_BRANCH, BOOK_LOAN
where BOOK.BookId = BOOK_LOAN.BookId and BOOK_LOAN.BranchId = LIBRARY_BRANCH.BranchId
and BORROWER.CardNo = BOOK_LOAN.CardNo and LIBRARY_BRANCH.BranchName = 'Sharpstown' and BOOK_LOAN.DueDate = 'today';

5. For each library branch, retrieve the branch name and the total number of books loaned out from that branch.

select BranchName, count(*) as "the total number of books loaned out"
from BOOK_LOAN
inner join LIBRARY_BRANCH.BranchId = BOOK_LOAN.BranchId
group by BranchName;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote