Consider the LIBRARY relational schema shown in Figure 6.14, which is used to keep track of books, borrowers, and book loans. Referential integrity constraints are shown as directed arcs in Figure 6.14, as in the notation of Figure 3.7. Write down relational expressions for the following queries on the LIBRARY database:
(a) How many copies of the book titled The Lost Tribe are owned by the library branch whose name is "Sharpstown"?
(b) How many copies of the book titled The Lost Tribe are owned by each library branch?
(c) Retrieve the names of all borrowers who do not have any books checked out.
(d) For each book that is loaned out from the "Sharpstown" branch and whose DueDate is today, retrieve the book title, the borrower's name, and the borrower's address.
(e) For each library branch, retrieve the branch name and the total number of books loaned out from that branch.
(f) Retrieve the names, addresses, and number of books checked out for all borrowers who have more than five books checked out.
(g) For each book authored (or co-authored) by "Stephen King", retrieve the title and the number of copies owned by the library branch whose name is "Central".
(Note: We will use S for SELECT, P for PROJECT, * for NATURAL JOIN, - for
SET DIFFERENCE, F for AGGREGATE FUNCTION)
(a) A <-- BOOKCOPIES * LIBRARY-BRANCH * BOOK
RESULT <-- P No_Of_Copies ( S BranchName='Sharpstown' and Title='The Lost
Tribe'
(A) )
Note: A better query would be to do the SELECTs before the JOIN as follows:
A <-- P No_Of_Copies ( ( S BranchName='Sharpstown' (LIBRARY-BRANCH) ) *
(BOOKCOPIES * ( S Title='The Lost Tribe'
(BOOK) ) ) )
(b) P BranchID,No_Of_Copies ( ( S Title='The Lost Tribe' (BOOK)) * BOOKCOPIES )
(c) NO_CHECKOUT_B <-- P CardNo (BORROWER) - P CardNo (BOOK_LOANS)
RESULT <-- P Name (BORROWER * NO_CHECKOUT_B)
(d) S <-- P BranchId ( S BranchName='Sharpstown' (LIBRARY-BRANCH) )
B_FROM_S <-- P BookId,CardNo ( ( S DueDate='today' (BOOKLOANS) ) * S )
RESULT <-- P Title,Name,Address ( BOOK * BORROWER * B_FROM_S )
(e) R(BranchId,Total) <-- BranchId FCOUNT(BookId,CardNo) (BOOK_LOANS)
RESULT <-- P BranchName,Total (R * LIBRARY_BRANCH)
(f) B(CardNo,TotalCheckout) <-- CardNo F COUNT(BookId) (BOOK_LOANS)
B5 <-- S TotalCheckout > 5 (B)
RESULT <-- P Name,Address,TotalCheckout ( B5 * BORROWER)
(g) SK(BookId,Title) <-- ( sAuthorName='Stephen King' ( BOOK_AUTHORS)) * BOOK
CENTRAL(BranchId) <-- sBranchName='Central' ( LIBRARY_BRANCH )
RESULT <-- P Title,NoOfCopies ( SK * BOOKCOPIES * CENTRAL )
You might also like to view...
If you have the following class definitions, which of the following is the proper way to construct an object of the derived class?
class Pet { public: Pet(); void printPet(); string getName(); void setName(string newName); private: string name; }; class Dog:public Pet { public: Dog(); void printPet(); void setType(string newType); string getType(); private: string type; }; a. Dog::Dog():Pet(),type("MUTT") { } b. Dog::Dog() { name="Rover"; } c. Pet::Dog():Pet(),type("MUTT") { } d. Dog::Pet():Pet(),type("MUTT") { }
If the Boolean expression A is True and B is False, the value of the logical expression A Or B is __________.
a. True b. False c. 1 d. 0
High-level assessment is a top-down look at the organization's policies, procedures, and guidelines
Indicate whether the statement is true or false.
Currently, there are two major techniques used to develop programs and their procedures. Name and describe them.
What will be an ideal response?