EECE 431 Homework, Spring 2008

American University of Beirut · Design and Analysis of Algorithms · 17 pages

All EECE 431 files
EECE 431 Homework, Spring 2008, page 1

Stuck on a question? A tutor can walk you through it.

EECE 431 Homework, Spring 2008, page 2 EECE 431 Homework, Spring 2008, page 3 EECE 431 Homework, Spring 2008, page 4 EECE 431 Homework, Spring 2008, page 5 EECE 431 Homework, Spring 2008, page 6 EECE 431 Homework, Spring 2008, page 7 EECE 431 Homework, Spring 2008, page 8 EECE 431 Homework, Spring 2008, page 9 EECE 431 Homework, Spring 2008, page 10

Showing the first 10 of 17 pages. Download the PDF to see all of it.

More EECE 431 files

Show the text of this homework
Chapter 6: The Relational Algebra and Relational Calculus CHAPTER 6: THE RELATIONAL ALGEBRA AND RELATIONAL CALCULUS Answers to Selected Exercises 6.15 Show the result of each of the example queries in Section 6.5 if they are applied to the database of Figure 5.6. Answer: (QUERY 1) Find the name and address of all employees who work for the 'Research' department. Result: FNAME LNAME ADDRESS John Smith 731 Fondren, Houston, TX Franklin Wong 638 Voss, Houston, TX Ramesh Narayan 975 Fire Oak, Humble, TX Joyce English 5631 Rice, Houston, TX (QUERY 2) For every project located in 'Stafford', list the project number, the controlling department number, and the department manager's last name, address, and birth date. Result: PNUMBER DNUM LNAME ADDRESS BDATE 10 4 Wallace 291 Berry, Bellaire, TX 20-JUN-31 30 4 Wallace 291 Berry, Bellaire, TX 20-JUN-31 (QUERY 3) Find the names of all employees who work on all the projects controlled by department number 5. Result: (empty because no tuples satisfy the result). LNAME FNAME (QUERY 4) Make a list of project numbers for projects that involve an employee whose last name is 'Smith' as a worker or as a manager of the department that controls the project. Result: PNO 1 2 (QUERY 5) List the names of all employees with two or more dependents. Result: LNAME FNAME Smith John Wong Franklin (QUERY 6) List the names of employees who have no dependents. Result: LNAME FNAME Zelaya Alicia Narayan Ramesh English Joyce Jabbar Ahmad Borg James (QUERY 7) List the names of managers who have at least one dependent. Pre-Publication Material: This is draft manuscript yet to be copy edited or paged. Copyright AWL2004 1 Chapter 6: The Relational Algebra and Relational Calculus Result: LNAME FNAME Wallace Jennifer Wong Franklin 6.16 Specify the following queries on the database schema shown in Figure 5.5 using the relational operators discussed in this chapter. Also show the result of each query if applied to the database of Figure 5.6. (a) Retrieve the names of employees in department 5 who work more than 10 hours per week on the 'ProductX' project. (b) List the names of employees who have a dependent with the same first name as themselves. (c) Find the names of employees that are directly supervised by 'Franklin Wong'. (d) For each project, list the project name and the total hours per week (by all employees) spent on that project. (e) Retrieve the names of employees who work on every project. (f) Retrieve the names of employees who do not work on any project. (g) For each department, retrieve the department name, and the average salary of employees working in that department. (h) Retrieve the average salary of all female employees. (i) Find the names and addresses of employees who work on at least one project located in Houston but whose department has no location in Houston. (j) List the last names of department managers who have no dependents. Answers: In the relational algebra, as in other languages, it is possible to specify the same query in multiple ways. We give one possible solution for each query. We use the symbol s for SELECT, P for PROJECT, J for EQUIJOIN, * for NATURAL JOIN, and f for FUNCTION. (a) EMP_W_X <-- ( s PNAME='ProductX' (PROJECT)) J (PNUMBER),(PNO) (WORKS_ON) EMP_WORK_10 <-- (EMPLOYEE) J (SSN),(ESSN) ( s HOURS>10 (EMP_W_X)) RESULT <-- P LNAME,FNAME ( s DNO=5 (EMP_WORK_10)) Result: LNAME FNAME Smith John English Joyce Pre-Publication Material: This is draft manuscript yet to be copy edited or paged. Copyright AWL2004 2 Chapter 6: The Relational Algebra and Relational Calculus (b) E <-- (EMPLOYEE) J (SSN,FNAME),(ESSN,DEPENDENT_NAME) (DEPENDENT) R <-- P LNAME,FNAME (E) Result (empty): LNAME FNAME (c) WONG_SSN <-- P SSN ( s FNAME='Franklin' AND LNAME='Wong' (EMPLOYEE)) WONG_EMPS <-- (EMPLOYEE) J (SUPERSSN),(SSN) (WONG_SSN) RESULT <-- P LNAME,FNAME (WONG_EMPS) Result: LNAME FNAME Smith John Narayan Ramesh English Joyce (d) PROJ_HOURS(PNO,TOT_HRS) <-- PNO f SUM HOURS (WORKS_ON) RESULT <-- P PNAME,TOT_HRS ( (PROJ_HOURS) J (PNO),(PNUMBER) (PROJECT) ) Result: PNAME TOT_HRS ProductX 52.5 ProductY 37.5 ProductZ 50.0 Computerization 55.0 Reorganization 25.0 Newbenefits 55.0 (e) PROJ_EMPS(PNO,SSN) <-- P PNO,ESSN (WORKS_ON) ALL_PROJS(PNO) <-- P PNUMBER (PROJECT) EMPS_ALL_PROJS <-- PROJ_EMPS -:- ALLPROJS (* DIVISION operation *) RESULT <-- P LNAME,FNAME (EMPLOYEE * EMP_ALL_PROJS) Result (empty): LNAME FNAME (f) ALL_EMPS <-- P SSN (EMPLOYEE) WORKING_EMPS(SSN) <-- P ESSN (WORKS_ON) NON_WORKING_EMPS <-- ALL_EMPS - WORKING_EMPS (* DIFFERENCE *) RESULT <-- P LNAME,FNAME (EMPLOYEE * NON_WORKING_EMPS) Result (empty): LNAME FNAME (g) DEPT_AVG_SALS(DNUMBER,AVG_SAL) <-- DNO f AVG SALARY Pre-Publication Material: This is draft manuscript yet to be copy edited or paged. Copyright AWL2004 3 Chapter 6: The Relational Algebra and Relational Calculus (EMPLOYEE) RESULT <-- P DNUMBER,AVG_SAL ( DEPT_AVG_SALS * DEPARTMENT ) Result: DNUMBER AVG_SAL Research 33250 Administration 31000 Headquarters 55000 (h) RESULT(AVG_F_SAL) <-- f AVG SALARY ( s SEX='F' (EMPLOYEE) ) Result: AVG_F_SAL 31000 (i) E_P_HOU(SSN) <-- P ESSN (WORKS_ON J(PNO),(PNUMBER) ( s PLOCATION='Houston' (PROJECT))) D_NO_HOU <-- P DNUMBER (DEPARTMENT) - P DNUMBER ( s DLOCATION='Houston' (DEPARTMENT)) E_D_NO_HOU <-- P SSN (EMPLOYEE J(PNO),(DNUMBER) (D_NO_HOU)) RESULT_EMPS <-- E_P_HOU - E_D_NO_HOU (* this is set DIFFERENCE *) RESULT <-- P LNAME,FNAME,ADDRESS (EMPLOYEE * RESULT_EMPS) Result: LNAME FNAME ADDRESS Wallace Jennifer 291 Berry, Bellaire, TX (j) DEPT_MANAGERS(SSN)<-- P MGRSSN (DEPARTMENT) EMPS_WITH_DEPENDENTS(SSN) <-- P ESSN (DEPENDENT) RESULT_EMPS <-- DEPT_MANAGERS - EMPS_WITH_DEPENDENTS RESULT <-- P LNAME,FNAME (EMPLOYEE * RESULT_EMPS) Result: LNAME FNAME Borg James 6.18 Consider the LIBRARY relational schema shown in Figure 7.20, which is used to keep track of books, borrowers, and book loans. Referential integrity constraints are shown as directed arcs in Figure 7.20, as in the notation of Figure 7.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. Pre-Publication Material: This is draft manuscript yet to be copy edited or paged. Copyright AWL2004 4 Chapter 6: The Relational Algebra and Relational Calculus (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". Answer: (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 ) 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) Pre-Publication Material: This is draft manuscript yet to be copy edited or paged. Copyright AWL2004 5 Chapter 6: The Relational Algebra and Relational Calculus 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 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: Pre-Publication Material: This is draft manuscript yet to be copy edited or paged. Copyright AWL2004 6 Chapter 6: The Relational Algebra and 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. Tuple relational Calculus: { e.LNAME, e.FNAME | EMPLOYEE(e) AND (FORALL p) ( NOT(PROJECT(p)) OR (EXISTS w) ( WORKS_ON(w) AND p.PNUMBER=w.PNO AND w.ESSN=e.SSN ) ) } Domain relational Calculus: { qs | (EXISTS t) ( EMPLOYEE(qrstuvwxyz) AND (FORALL b) ( NOT(PROJECT(abcd)) OR (EXISTS e) (EXISTS f) (WORKS_ON(efg) AND e=t AND f=b) ) } (f) Retrieve the names of employees who do not work on any project. Tuple relational Calculus: { e.LNAME, e.FNAME | EMPLOYEE(e) AND NOT(EXISTS w) ( WORKS_ON(w) AND w.ESSN=e.SSN ) } Domain relational Calculus: { qs | (EXISTS t) ( EMPLOYEE(qrstuvwxyz) AND NOT(EXISTS a) ( WORKS_ON(abc) AND a=t ) ) } (i) Find the names and addresses of employees who work on at least one project located in Houston but whose department has no location in Houston. Tuple relational Calculus: { e.LNAME, e.FNAME, e.ADDRESS | EMPLOYEE(e) AND (EXISTS p) (EXISTS w) ( WORKS_ON(w) AND PROJECT(p) AND e.SSN=w.ESSN AND w.PNO=p.PNUMBER AND p.PLOCATION='Houston' AND NOT(EXISTS l) ( DEPT_LOCATIONS(l) AND e.DNO=l.DNUMBER AND l.DLOCATION='Houston' ) ) } Domain relational Calculus: Pre-Publication Material: This is draft manuscript yet to be copy edited or paged. Copyright AWL2004 7 Chapter 6: The Relational Algebra and Relational Calculus { qsv | (EXISTS t) (EXISTS z) ( EMPLOYEE(qrstuvwxyz) AND (EXISTS b) (EXISTS c) (EXISTS e) (EXISTS f) ( WORKS_ON(efg) AND PROJECT(abcd) AND t=e AND f=b AND c='Houston' AND NOT(EXISTS h) NOT(EXISTS i) ( DEPT_LOCATIONS(hi) AND z=h AND i='Houston' ) ) } (j) List the last names of department managers who have no dependents. Tuple relational Calculus: { e.LNAME | EMPLOYEE(e) AND (EXISTS d) ( DEPARTMENT(d) AND e.SSN=d.MGRSSN AND NOT(EXISTS x) (DEPENDENT(x) AND e.SSN=x.ESSN) ) } Domain relational Calculus: { s | (EXISTS t) ( EMPLOYEE(qrstuvwxyz) AND (EXISTS c) ( DEPARTMENT(abcd) AND t=c AND NOT(EXISTS e) (DEPENDENT(efghi) AND e=t) ) } 6.25 No solution provided. 6.26 Specify queries of Exercise 6.18 in both the tuple relational calculus and the domain relational calculus. Also specify these queries in the relational algebra. Answer: We will only do tuple and domain relational calculus here. (a) Retrieve the names of all senior students majoring in 'COSC' (computer science). Tuple relational Calculus: { s.Name | STUDENT(s) AND AND s.Class=5 AND s.Major='COSC' } Domain relational Calculus: { a | (EXISTS c) (EXISTS d) ( STUDENT(abcd) AND c=5 AND d='COSC' ) } (b) Retrieve the names of all courses taught by professor King in 85 and 86. Tuple relational Calculus: { c.CourseName | COURSE(c) AND (EXISTS s) ( SECTION(s) AND c.CourseNumber=s.CourseNumber AND s.Instructor='King' AND ( s.Year='85' OR s.Year='86' ) ) } Domain relational Calculus: { a | (EXISTS b) (EXISTS f) (EXISTS h) (EXISTS i) ( COURSE(abcd) AND SECTION(efghi) AND f=b AND i='King' AND ( h='85' OR h='86' ) ) } (c) For each section taught by professor King, retrieve the course number, semester, year, and number of students who took the section. This query cannot be done in basic relational calculus as it requires a COUNT function. Pre-Publication Material: This is draft manuscript yet to be copy edited or paged. Copyright AWL2004 8 Chapter 6: The Relational Algebra and Relational Calculus (d) Retrieve the name and transcript of each senior student (Class=5) majoring in COSC. Transcript includes course name, course number, credit hours, semester, year, and grade for each course completed by the student. Tuple relational Calculus: {s.Name, c.CourseName, c.CourseNumber, c.CreditHours, t.Semester, t.Year, g.Grade | STUDENT(s) AND COURSE(c) AND SECTION(t) AND GRADE_REPORT(g) AND s.Class=5 AND s.Major='COSC' AND s.StudentNumber=g.StudentNumber AND g.SectionIdentifier=t.SectionIdentifier AND t.CourseNumber=c.CourseNumber} Domain relational Calculus: {aefgklp | (EXISTS b) (EXISTS c) (EXISTS d) (EXISTS n) (EXISTS o) (EXISTS j) (EXISTS i) (STUDENT(abcd) AND COURSE(efgh) AND SECTION(ijklm) AND GRADE_REPORT(nop) AND c=5 AND d='COSC' AND b=n AND i=o AND j=f)} (e) Retrieve the names and major departments of all straight A students (students who have a grade of A in all their courses). Tuple relational Calculus: { s.Name, s.Major | STUDENT(s) AND (FORALL g) ( NOT(GRADE_REPORT(g)) OR NOT(s.StudentNumber=g.StudentNumber) OR g.Grade='A' ) } Domain relational Calculus: { ad | (EXISTS b) ( STUDENT(abcd) AND (FORALL e) (FORALL g) ( NOT(GRADE_REPORT(efg)) OR NOT(b=e) OR g='A' ) ) } (f) Retrieve the names and major departments of all students who do not have any grade of A in any of their courses. Tuple relational Calculus: { s.Name, s.Major | STUDENT(s) AND NOT(EXISTS g) ( GRADE_REPORT(g) AND s.StudentNumber=g.StudentNumber AND g.Grade='A' ) } Domain relational Calculus: { ad | (EXISTS b) ( STUDENT(abcd) AND NOT(EXISTS e) NOT(EXISTS g) ( GRADE_REPORT(efg) AND b=e AND g='A' ) ) } 6.27 In a tuple relational calculus query with n tuple variables, what would be the typical minimum number of join conditions? Why? What is the effect of having a smaller number of join conditions? Answer: Typically, there should be at least (n-1) join conditions; otherwise, a cartesian product with one of the range relations would be taken, which usually does not make sense. 6.28 Rewrite the domain relational calculus queries that followed Q0 in Section 6.7 in Pre-Publication Material: This is draft manuscript yet to be copy edited or paged. Copyright AWL2004 9 Chapter 6: The Relational Algebra and Relational Calculus the style of the abbreviated notation of Q0A, where the objective is to minimize the number of domain variables by writing constants in place of variables wherever possible. Answer: Q1A: { qsv | (EXISTS z) (EXISTS m) ( EMPLOYEE(q,r,s,t,u,v,w,x,y,z) AND DEPARTMENT('Research',m,n,o) AND m=z ) } Q2A: { iksuv | (EXISTS m) (EXISTS n) (EXISTS t) ( PROJECT(h,i,'Stafford',k) AND EMPLOYEE(q,r,s,t,u,v,w,x,y,z) AND DEPARTMENT(l,m,n,o) ) } The other queries will not be different since they have no constants (no selection conditions; only join conditions) 6.30 Show how you may specify the following relational algebra operations in both tuple and domain relational calculus. (a) SELECT A=c (R(A, B, C)): (b) PROJECT <A, B> (R(A, B, C)): (c) R(A, B, C) NATURAL JOIN S(C, D, E): (d) R(A, B, C) UNION S(A, B, C): (e) R(A, B, C) INTERSECT S(A, B, C): (f) R(A, B, C) MINUS S(A, B, C): (g) R(A, B, C) CARTESIAN PRODUCT S(D, E, F): (h) R(A, B) DIVIDE S(A): Answer: For each operation, we give the tuple calculus expression followed by the domain calculus expression. (a) { t | R(t) AND t.A=c}, { xyz | R(xyz) AND x=c } (b) { t.A, t.B | R(t) }, { xy | R(xyz) } (c) {t.A, t.B, t.C, q.D, q.E | R(t) AND S(q) AND t.C=q.C }, { xyzvw | R(xyz) AND (EXISTS u) ( S(uvw) AND z=u ) } (d) { t | R(t) OR S(t) }, { xyz | R(xyz) OR S(xyz) } (e) { t | R(t) AND S(t) }, { xyz | R(xyz) AND S(xyz) } Pre-Publication Material: This is draft manuscript yet to be copy edited or paged. Copyright AWL2004 10 Chapter 6: The Relational Algebra and Relational Calculus (f) { t | R(t) AND NOT(S(t)) }, { xyz | R(xyz) AND NOT(S(xyz)) } (g) { t.A, t.B, t.C, q.D, q.E, q.F | R(t) AND S(q) }, ( xyzuvw | R(xyz) AND S(uvw) } (h) { t.B | R(t) AND (FORALL s) ( NOT(S(s)) OR (EXISTS q) ( R(q) AND s.A=q.A AND q.B=t.B ) ) }, { y | R(xy) AND (FORALL z) ( NOT(S(z)) OR (EXISTS u) ( R(uy) AND z=u ) } Pre-Publication Material: This is draft manuscript yet to be copy edited or paged. Copyright AWL2004 11 Chapter 7: Relational Database Design by ER- and EER-to-Relational Mapping CHAPTER 7: RELATIONAL DATABASE DESIGN BY ER- AND EER-TO- RELATIONAL MAPPING Answers to Selected Exercises 7.3 Try to map the relational schema of Figure 6.12 into an ER schema. This is part of a process known as reverse engineering, where a conceptual schema is created for an existing implemented database. State any assumptions you make. Answer: Note: We represented BOOK_AUTHORS as a multi-valued attribute of BOOK in the above ER diagram. Alternatively, it can be represented as a weak entity type. 7.4 Figure 7.7 shows an ER schema for a database that may be used to keep track of transport ships and their locations for maritime authorities. Map this schema into a relational schema, and specify all primary keys and foreign keys. Answer: SHIP SNAME OWNER TYPE PNAME SHIP_TYPE TYPE TONNAGE HULL STATE_COUNTRY NAME CONTINENT SEAOCEANLAKE NAME Pre-Publication Material: This is draft manuscript yet to be copy edited or paged. Copyright AWL2004 1 Chapter 7: Relational Database Design by ER- and EER-to-Relational Mapping SHIP_MOVEMENT SSNAME DATE TIME LONGITUDE LATITUTE PORT S_C_NAME PNAME S_O_L_NAME VISIT VSNAME VPNAME STARTDATE ENDDATE f.k. f.k. f.k. f.k. f.k. f.k. f.k. 7.5 Map the BANK ER schema of Exercise 3.23 (shown in Figure 3.17) into a relational schema. Specify all primary keys and foreign keys. Repeat for the AIRLINE schema (Figure 3.16) of Exercise 3.19 and for the other schemas for Exercises 3.16 through 3.24. Partial Answer: BANK CODE NAME ADDR ACCOUNT ACCTNO BALANCE TYPE BCODE BNO CUSTOMER SSN NAME PHONE ADDR LOAN LOANNO AMOUNT TYPE BCODE BNO BANK_BRANCH BCODE BRANCHNO ADDR A_C SSN ACCTNO L_C SSN LOANNO f.k. f.k. f.k. f.k. f.k. f.k. f.k. f.k. f.k. Pre-Publication Material: This is draft manuscript yet to be copy edited or paged. Copyright AWL2004 2 CS542 / 442 Database Systems I - Fall 2007 Homework #2 Assigned date : 10/3/2007 Due date : 10/17/2007 Total Points : 200 ----------------------------------------------------------------------------------------- Solve Following problems : Question 1 - 5.11 (50 points) Suppose each of the following update operations is applied directly to the database of Figure 5.6. Discuss all integrity constraints violated by each operation, if any, and the different ways of enforcing these constraints: (a) Insert < 'Robert', 'F', 'Scott', '943775543', '21-JUN-42', '2365 Newcastle Rd, Bellaire, TX', M, 58000, '888665555', 1 > into EMPLOYEE. (b) Insert < 'ProductA', 4, 'Bellaire', 2 > into PROJECT. (c) Insert < 'Production', 4, '943775543', '01-OCT-88' > into DEPARTMENT. (d) Insert < '677678989', null, '40.0' > into WORKS_ON. (e) Insert < '453453453', 'John', M, '12-DEC-60', 'SPOUSE' > into DEPENDENT. (f) Delete the WORKS_ON tuples with ESSN= '333445555'. (g) Delete the EMPLOYEE tuple with SSN= '987654321'. (h) Delete the PROJECT tuple with PNAME= 'ProductX'. (i) Modify the MGRSSN and MGRSTARTDATE of the DEPARTMENT tuple with DNUMBER=5 to '123456789' and '01-OCT-88', respectively. (j) Modify the SUPERSSN attribute of the EMPLOYEE tuple with SSN= '999887777' to '943775543'. (k) Modify the HOURS attribute of the WORKS_ON tuple with ESSN= '999887777' and PNO= 10 to '5.0'. Question 2 - 5.14 (25 points) Consider the following six relations for an order-processing database application in a company: CUSTOMER (Cust#, Cname, City) ORDER (Order#, Odate, Cust#, Ord_Amt) ORDER_ITEM (Order#, Item#, Qty) ITEM (Item#, Unit_price) SHIPMENT (Order#, Warehouse#, Ship_date) WAREHOUSE (Warehouse#, City) Here, Ord_Amt refers to total dollar amount of an order; Odate is the date the order was placed; Ship_date is the date an order is shipped from the warehouse. Assume that an order can be shipped from several warehouses. Specify foreign keys for this schema, stating any assumptions you make. Question 3: (50 points) Figure 7.8 shows an ER schema for a database that may be used to keep track of transport ships and their locations for maritime authorities. Map this schema into a relational schema, and specify all primary keys and foreign keys. Question 4 - 6.16 (ANY FIVE 50 points) Specify the following queries on the COMPANY relational database schema shown in Figure 5.5, using the relational operators discussed in chapter 6. Also show the result of each query as it would apply to the database state of Figure 5.6. (a) Retrieve the names of employees in department 5 who work more than 10 hours per week on the 'ProductX' project. (b) List the names of employees who have a dependent with the same first name as themselves. (c) Find the names of employees that are directly supervised by 'Franklin Wong'. (d) For each project, list the project name and the total hours per week (by all employees) spent on that project. (e) Retrieve the names of employees who work on every project. (f) Retrieve the names of employees who do not work on any project. (g) For each department, retrieve the department name, and the average salary of employees working in that department. (h) Retrieve the average salary of all female employees. (i) Find the names and addresses of employees who work on at least one project located in Houston but whose department has no location in Houston. (j) List the last names of department managers who have no dependents. Question 5 - 6.18 (ANY FIVE 25 points) 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 5.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". Question 6 - 6.36 (25 points) Consider the following GRADEBOOK relational schema describing the data for a grade book of a particular instructor (Note: The attributes A, B, C, and D store grade cutoffs.) catalogue(cno,ctitle) students(sid,fname,lname,minit) courses(term,secno,cno,A,B,C,D) enrolls(sid,term,secno) Specify and execute the following queries using the MySQL database on windom and the GRADEBOOK database schema. a. Retrieve the names of students enrolled in the ‘Automata’ class in the term of Fall 1996. b. Retrieve the SID values of students who have enrolled in csc226 as well as csc227. c. Retrieve the SID values of students who have enrolled in csc226 or csc227. d. Retrieve the names of students who have not enrolled in any class. e. Retrieve the names of students who have enrolled in all courses in the catalogue table. Please ignore sub-part e above.