library database with the following schema primary keys are Bolded Book( bookID
ID: 3754438 • Letter: L
Question
library database with the following schema
primary keys are Bolded
Book(bookID, ISBN, title, author, publish-year, category)
Member(memberID, lastname, firstname, address, phone-number, limit)
CurrentLoan(memberID, bookID, loan-date, due-date)
History(memberID, bookID, loan-date, return-date)
Members can borrow books from the library. The number of books they can borrow is limited
by the “limit” field of the Member relation. The category of a book includes fiction, non-fiction,
children’s and reference. The CurrentLoan table represents the information about books that
are currently checked out. When the book is returned to the library, the record will be removed
from CurrentLoad relation, and will be inserted into History relation with the return-date. A
library may have more than one copy of the same book, in which case each copy has its own
bookID, but all copies share the same ISBN.
Express each of the following tasks in relational algebra.
(1) (4 pts) Find the memberID, address, and phone-number of John Smith.
(2) (8 pts) List the bookID and title of all the books that are currently checked out by John
Smith. Do not use any natural join in this query.
(3) (8 pts) List the bookID and title of all the books that are either currently checked out or
borrowed in the past by John Smith.
(4) (6 pts) Find the bookID and title of all the books that are not currently checked out.
(5) (8 pts) List the first and last names of members who have borrowed (either currently or in
the past) all the books in the library that are authored by Arthur Miller. If some books
authored by Arthur Miller have multiple copies, he or she must have borrowed at least one
copy of each of Arthur Miller’s books.
(6) (6 pts) For each member, find the total number of books currently being checked out (write
a single query for this question).
Explanation / Answer
Here given database tables is
Book(bookID, ISBN, title, author, publish-year, category)
Member(memberID, lastname, firstname, address, phone-number, limit)
CurrentLoan(memberID, bookID, loan-date, due-date)
History(memberID, bookID, loan-date, return-date)
1)memberID, address, and phone-number ( firstname='john' ^ lastname='smith'(Member ))
In the above query in inner query we will select the tuple with firstname ='john' and lastname='smith' and from that we will select memberID, address, and phone-number attributes.
2)bookID,title (bookID (CurrentLoan ^ (memberID( firstname='john' ^ lastname='smith'(Member )))))^(Book )
here we used inner query concept memberID( firstname='john' ^ lastname='smith'(Member ))) it selects the the tuple with firstname ='john' and lastname='smith' and from that we will select memberID using this and CurrentLoan table we will find the bookid and using this and table book we will select bookID,title attributes.
3)bookID,title(Book x Currentloan x History)
The above query involves the cross product of the three tables and from cross product of three tables we will select the tuples bookID and title.
4)bookID,title(bookID,title(Book)-bookID,title(CurrentLoan))
Here we have used set difference operator the query bookID,title(Book) selects all the books and bookID,title(CurrentLoan) selects all the queries that are checked out and bookID,title(Book)-bookID,title(CurrentLoan) gives all the books books that are not currently checked out.We will project bookID and title from those
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.