DOC PREVIEW
UT Dallas CS 6385 - Elm04_06

This preview shows page 1-2-3-4 out of 11 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Chapter 6: The Relational Algebra and Relational CalculusCHAPTER 6: THE RELATIONAL ALGEBRA AND RELATIONAL CALCULUSAnswers to Selected Exercises6.15 Show the result of each of the example queries in Section 6.5 if they are applied tothe 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 ADDRESSJohn Smith 731 Fondren, Houston, TXFranklin Wong 638 Voss, Houston, TXRamesh Narayan 975 Fire Oak, Humble, TXJoyce English 5631 Rice, Houston, TX(QUERY 2) For every project located in 'Stafford', list the project number, thecontrolling department number, and the department manager's last name, address, andbirth date.Result:PNUMBER DNUM LNAME ADDRESS BDATE10 4 Wallace 291 Berry, Bellaire, TX 20-JUN-3130 4 Wallace 291 Berry, Bellaire, TX 20-JUN-31(QUERY 3) Find the names of all employees who work on all the projects controlled bydepartment 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 whoselast name is 'Smith' as a worker or as a manager of the department that controls theproject.Result: PNO12(QUERY 5) List the names of all employees with two or more dependents.Result: LNAME FNAMESmith JohnWong Franklin(QUERY 6) List the names of employees who have no dependents.Result: LNAME FNAMEZelaya AliciaNarayan RameshEnglish JoyceJabbar AhmadBorg 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 AWL20041Chapter 6: The Relational Algebra and Relational CalculusResult: LNAME FNAMEWallace JenniferWong Franklin6.16 Specify the following queries on the database schema shown in Figure 5.5 usingthe relational operators discussed in this chapter. Also show the result of eachquery if applied to the database of Figure 5.6.(a) Retrieve the names of employees in department 5 who work more than 10 hours perweek on the 'ProductX' project.(b) List the names of employees who have a dependent with the same first name asthemselves.(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 allemployees) 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 ofemployees 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 locatedin 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 queryin multiple ways. We give one possible solution for each query. We use the symbol s forSELECT, 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 FNAMESmith JohnEnglish JoycePre-Publication Material: This is draft manuscript yet to be copy edited or paged.Copyright AWL20042Chapter 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' ANDLNAME='Wong' (EMPLOYEE))WONG_EMPS <-- (EMPLOYEE) J (SUPERSSN),(SSN) (WONG_SSN)RESULT <-- P LNAME,FNAME (WONG_EMPS)Result:LNAME FNAMESmith JohnNarayan RameshEnglish 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_HRSProductX 52.5ProductY 37.5ProductZ 50.0Computerization 55.0Reorganization 25.0Newbenefits 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 SALARYPre-Publication Material: This is draft manuscript yet to be copy edited or paged.Copyright AWL20043Chapter 6: The Relational Algebra and Relational Calculus(EMPLOYEE)RESULT <-- P DNUMBER,AVG_SAL ( DEPT_AVG_SALS * DEPARTMENT )Result:DNUMBER AVG_SALResearch 33250Administration 31000Headquarters 55000(h) RESULT(AVG_F_SAL) <-- f AVG SALARY ( s SEX='F' (EMPLOYEE) )Result:AVG_F_SAL31000(i) E_P_HOU(SSN) <--P ESSN (WORKS_ON J(PNO),(PNUMBER) ( s PLOCATION='Houston' (PROJECT)))D_NO_HOU <--P DNUMBER (DEPARTMENT) - P DNUMBER ( sDLOCATION='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 ADDRESSWallace 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_DEPENDENTSRESULT <-- P LNAME,FNAME (EMPLOYEE * RESULT_EMPS)Result:LNAME FNAMEBorg James6.18 Consider the LIBRARY relational schema shown in Figure 7.20, which is used tokeep track of books, borrowers, and book loans. Referential integrity constraints areshown as directed arcs in Figure 7.20, as in the notation of Figure 7.7. Write downrelational 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 branchwhose name is "Sharpstown"?(b) How many copies of the book titled The Lost Tribe are owned by each librarybranch?(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 AWL20044Chapter 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


View Full Document

UT Dallas CS 6385 - Elm04_06

Documents in this Course
assn1

assn1

2 pages

38rel2

38rel2

5 pages

Report

Report

3 pages

networks

networks

18 pages

lp2

lp2

44 pages

lp2 (2)

lp2 (2)

27 pages

lp1(1)

lp1(1)

21 pages

integer1

integer1

50 pages

FrankR2

FrankR2

3 pages

duality

duality

28 pages

CMST

CMST

44 pages

hw4

hw4

3 pages

for 1

for 1

11 pages

ENCh02

ENCh02

33 pages

pree

pree

2 pages

new  3

new 3

2 pages

new  2

new 2

2 pages

hw4a

hw4a

2 pages

T2_Sol

T2_Sol

4 pages

ISM3

ISM3

8 pages

hw4_sol

hw4_sol

6 pages

atn proj2

atn proj2

20 pages

12CUT1

12CUT1

8 pages

09Ford

09Ford

23 pages

08FLOW

08FLOW

6 pages

03LP_su

03LP_su

6 pages

40REL40

40REL40

5 pages

39rel3

39rel3

5 pages

38arel2

38arel2

5 pages

37REL1

37REL1

3 pages

24TABU

24TABU

3 pages

22DYNPR

22DYNPR

3 pages

21B&C

21B&C

2 pages

20BBEX0

20BBEX0

3 pages

19BB

19BB

5 pages

14CAPBUD0

14CAPBUD0

11 pages

35BRXCH

35BRXCH

2 pages

34COMB

34COMB

4 pages

32CAPAS

32CAPAS

4 pages

31QUEUE

31QUEUE

3 pages

Load more
Download Elm04_06
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Elm04_06 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Elm04_06 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?