DOC PREVIEW
UT Dallas CS 6385 - DB2007HW03Answer

This preview shows page 1-2 out of 7 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 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 7 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1 2007 Spring Database Systems Homework III 參考解答 1. Specify the following queries on the COMPANY relational database schema shown in Figure 5.5, using the relational operators discussed in this chapter. 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. 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. (a) EMP_W_X ← ( σσσσ PNAME='ProductX' (PROJECT)) PNUMBER=PNO (WORKS_ON) EMP_WORK_10 ← (EMPLOYEE) SSN=ESSN (σσσσ HOURS>10 (EMP_W_X)) RESULT ← Π LNAME,FNAME (σσσσ DNO=5 (EMP_WORK_10)) Result: LNAME FNAME Smith John English Joyce2 (b) E ← (EMPLOYEE) SSN=ESSN AND FNAME=DEPENDENT_NAME (DEPENDENT) R ← Π LNAME,FNAME (E) Result (empty): LNAME FNAME (c) WONG_SSN ← Π SSN (σσσσ FNAME='Franklin' AND LNAME='Wong' (EMPLOYEE)) WONG_EMPS ← (EMPLOYEE) SUPERSSN=SSN (WONG_SSN) RESULT ← Π LNAME,FNAME (WONG_EMPS) Result: LNAME FNAME Smith John Narayan Ramesh English Joyce (d) PROJ_HOURS(PNO,TOT_HRS) ← PNO ℑ SUM HOURS (WORKS_ON) RESULT ← Π PNAME,TOT_HRS ( (PROJ_HOURS) 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) ← Π PNO,ESSN (WORKS_ON) ALL_PROJS(PNO) ← Π PNUMBER (PROJECT) EMPS_ALL_PROJS ← PROJ_EMPS ÷ ALLPROJS RESULT ← Π LNAME,FNAME (EMPLOYEE * EMP_ALL_PROJS) Result (empty): LNAME FNAME (f) ALL_EMPS ← Π SSN (EMPLOYEE) WORKING_EMPS(SSN) ← Π ESSN (WORKS_ON)3 NON_WORKING_EMPS ← ALL_EMPS - WORKING_EMPS RESULT ← Π LNAME,FNAME (EMPLOYEE * NON_WORKING_EMPS) Result (empty): LNAME FNAME (g) DEPT_AVG_SALS(DNUMBER,AVG_SAL) ← DNO ℑ AVG SALARY (EMPLOYEE) RESULT ← Π DNAME,AVG_SAL ( DEPT_AVG_SALS * DEPARTMENT ) Result: DNAME AVG_SAL Research 33250 Administration 31000 Headquarters 55000 (h) RESULT(AVG_F_SAL) ← ℑAVG SALARY (σσσσ SEX='F' (EMPLOYEE) ) Result: AVG_F_SAL 31000 (i) E_P_HOU(SSN) ← Π ESSN (WORKS_ON PNO=PNUMBER (σσσσ PLOCATION='Houston' (PROJECT))) D_NO_HOU ← Π DNUMBER (DEPARTMENT) - Π DNUMBER (σσσσ DLOCATION='Houston' (DEPARTMENT)) E_D_NO_HOU ← Π SSN (EMPLOYEE PNO=DNUMBER (D_NO_HOU)) RESULT_EMPS ← E_P_HOU - E_D_NO_HOU RESULT ← Π LNAME,FNAME,ADDRESS (EMPLOYEE * RESULT_EMPS) Result: LNAME FNAME ADDRESS Wallace Jennifer 291 Berry, Bellaire, TX (j) DEPT_MANAGERS(SSN) ← Π MGRSSN (DEPARTMENT) EMPS_WITH_DEPENDENTS(SSN) ← Π ESSN (DEPENDENT)4 RESULT_EMPS ← DEPT_MANAGERS - EMPS_WITH_DEPENDENTS RESULT ← Π LNAME,FNAME (EMPLOYEE * RESULT_EMPS) Result: LNAME FNAME Borg James 2. (a) R1 ←STUDENT S.SSN=E.SSN ENROLL R2 ← Π COURSE# σσσσ NAME=’JOHN SMITH’AND QUARTER=’W99’(R1)) Answer: R2 (b) R1← COURSE C.COURSE#=B.COURSE# BOOK_ADOPTION R2(COURSE#, BOOK_NO) ← COURSE # ℑ COUNT BOOK_ISBN (R1) R3←σσσσCNAME=’CS’AND BOOK_NO>2 (COURSE C.COURSE#=R2.COURSE# R2) R4← Π COURSE#, BOOK_ISBN (R3 R3.COURSE#=B.COURSE# BOOK_ADOPTION) R5← Π COURSE#, BOOK_ISBN, BOOK_TITLE (R4 R4.BOOK_ISBN=T.BOOK_ISBN TEXT) Answer: R5 (c) R1← Π COURSE#, PUBLISHER (BOOK_ADOPTION B.BOOK_ISBN=T.BOOK_ISBN TEXT) R2←σσσσ COUNT_PUB=’1’ (COURSE# ℑ COUNT PUBLISHER (R1)) R3←σσσσ PUBLISHER=’AWL Publishing’ (R2 R2.COURSE#=R1.COURSE# R1) R4← Π CNAME (COURSE C.COURSE#=R3.COURSE# R3) Answer: R45 3. Answer: (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 25 a 6 10b 6 25 c 3 10b 5 (f) P Q R A B C 10 a 5 10 b 5 4. Specify queries (a), (b), (c), (e), (f), (i), and (j) of Question 1 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 (∃ p) (∃ 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:6 { qs | EMPLOYEE(qrstuvwxyz) AND z=5 AND (∃ a) (∃ b) (∃ e) (∃ f) (∃ 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 (∃ d) ( DEPENDENT(d) AND e.SSN=d.ESSN AND e.FNAME=d.DEPENDENT_NAME ) } Domain relational Calculus: { qs | (∃ t) (∃ a) (∃ 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 (∃ s) ( EMPLOYEE(s) AND s.FNAME='Franklin' AND s.LNAME='Wong' AND e.SUPERSSN=s.SSN ) } Domain relational Calculus: { qs | (∃ y) (∃ a) (∃ c) (∃ 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,


View Full Document

UT Dallas CS 6385 - DB2007HW03Answer

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

Elm04_06

Elm04_06

11 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 DB2007HW03Answer
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 DB2007HW03Answer 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 DB2007HW03Answer 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?