F retrieve the names addresses and number of books

Info icon This preview shows pages 4–7. Sign up to view the full content.

View Full Document Right Arrow Icon
(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". Answer: (Note: We will use S for SELECT, P for PROJECT, * for NATURAL JOIN, - for
Image of page 4

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
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 ) 6.22 (a) P Q R A B C 10 a 5 10 b 6 10 a 5 10 b 5 25 a 6 25 c 3 (b) P Q R A B C 15 b 8 10 b 6 15 b 8 10 b 5 (c) P Q R A B C 10 a 5 10 b 6 10 a 5 10 b 5 15 b 8 null null null 25 a 6 25 c 3 (d) P Q R A B C 15 b 8 10 b 6 null null null 25 c 3 15 b 8 10 b 5 (e) P Q R 10a 5 15 b 8
Image of page 5
25 a 6 10b 6 25 c 3 10b 5 (f) P Q R A B C 10 a 5 10 b 5 6.24 Specify queries (a), (b), (c), (e), (f), (i), and (j) of Exercise 6.16 in both the tuple relational calculus and the domain relational calculus. Answer: (a) Retrieve the names of employees in department 5 who work more than 10 hours per week on the 'ProductX' project. Tuple relational Calculus: { e.LNAME, e.FNAME | EMPLOYEE(e) AND e.DNO=5 AND (EXISTS p) (EXISTS w) ( WORKS_ON(w) AND PROJECT(p) AND e.SSN=w.ESSN AND w.PNO=p.PNUMBER AND p.PNAME='ProductX' AND w.HOURS>10 ) } Domain relational Calculus: { qs | EMPLOYEE(qrstuvwxyz) AND z=5 AND (EXISTS a) (EXISTS b) (EXISTS e) (EXISTS f) (EXISTS g) ( WORKS_ON(efg) AND PROJECT(abcd) AND t=e AND f=b AND a='ProductX' AND g>10 ) } (b) List the names of employees who have a dependent with the same first name as themselves. Tuple relational Calculus: { e.LNAME, e.FNAME | EMPLOYEE(e) AND (EXISTS d) ( DEPENDENT(d) AND e.SSN=d.ESSN AND e.FNAME=d.DEPENDENT_NAME ) } Domain relational Calculus: { qs | (EXISTS t) (EXISTS a) (EXISTS b) ( EMPLOYEE(qrstuvwxyz) AND DEPENDENT(abcde) AND a=t AND b=q ) } (c) Find the names of employees that are directly supervised by 'Franklin Wong'. Tuple relational Calculus: { e.LNAME, e.FNAME | EMPLOYEE(e) AND (EXISTS s) ( EMPLOYEE(s) AND s.FNAME='Franklin' AND s.LNAME='Wong' AND e.SUPERSSN=s.SSN ) } Domain relational Calculus: { qs | (EXISTS y) (EXISTS a) (EXISTS c) (EXISTS d) ( EMPLOYEE(qrstuvwxyz) AND EMPLOYEE(abcdefghij) AND a='Franklin' AND c='Wong' AND y=d ) } (e) Retrieve the names of employees who work on every project.
Image of page 6

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern