Presentation is loading. Please wait.

Presentation is loading. Please wait.

Exercise 2 Relational Calculus Database System-dww.

Similar presentations


Presentation on theme: "Exercise 2 Relational Calculus Database System-dww."— Presentation transcript:

1 Exercise 2 Relational Calculus Database System-dww

2 6 Relations of Company

3 Find the first and last names of all employees whose salary is above $50,000 Database System-dww Rel Algebra  FNAME,LNAME(SALARY>‘50000’ (EMPLOYEES)) Tuple Rel Calculus  t.FNAME,t.LNAME|EMPLOYEE (x ) AND t.SALARY>‘50000’)) SQL  select FNAME, LNAME from EMPLOYEES where SALARY>‘50000’ Domain Rel Calculus  ac| ( Ǝ i) EMPLOYEE (abcdefghijkl ) AND i>‘50000’))

4 Database System-dww Exercises (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'. (e) Retrieve the names of employees who work on every project.

5 Database System-dww Exercises (f) Retrieve the names of employees who do not work on any project. (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.

6 Retrieve the names of employees in department 5 who work more than 10 hours per week on the 'ProductX' project Graphical approach can be used to help the logical and prosedural approach Example of above query, the graphical approach: clue from query the relations that (may) work on the query are in the red text Database System-dww P ProductX Pname=‘ProductX’ WE > 10 Hours > 10 Pnumber=Pno 5 Dno = 5 ESSN=SSN Fname, Lname (?) WORKS_ON_ProductX (Rel.A)  (PNAME=‘ProductX’(PROJECT) PNUMBER=PNO(WORKS_ON)) EMPLOYEE_DEPT5_WORKS_MORE_10_onProductX (Rel.B)  ((EMPLOYEE) SSN=ESSN(HOURS>10(Rel.A))) RESULT  FNAME,LNAME(DNO=‘5’ (Rel.B))

7 Retrieve the names of employees in department 5 who work more than 10 hours per week on the 'ProductX' project Database System-dww P ProductX Pname=‘ProductX’ WE > 10 Hours > 10 Pnumber=Pno 5 Dno = 5 ESSN=SSN Fname, Lname (?) { 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 ) } { 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 ) }

8 List the names of employees who have a dependent with the same first name as themselves. Database System-dww DpE Depend_name=Fname Fname, Lname (?) ESSN=SSN RESULT  FNAME,LNAME(DEPENDENT (ESSN,DEPEND_NAME)=(SSN,FNAME)(EMPLOYEE)) { e.LNAME, e.FNAME | EMPLOYEE(e) AND ( Ǝ d) ( DEPENDENT(d) AND e.SSN=d.ESSN AND e.FNAME=d.DEPENDENT_NAME ) } { qs | ( Ǝ t) ( Ǝ a) ( Ǝ b) ( EMPLOYEE(qrstuvwxyz) AND DEPENDENT(abcde) AND a=t AND b=q ) }

9 Find the names of employees that are directly supervised by 'Franklin Wong'. Database System-dww E_SSN_FRANKLIN_WONG(Rel.A)  (SSN(FNAME=‘FRANKLIN’ LNAME=‘WONG’(EMPLOYEE))) E_SUPERVISED_BY_FRANKLIN_WONG (Result)  (FNAME, LNAMES(EMPLOYEE) SUPERSSN=SSN(Rel.A)) { e.LNAME, e.FNAME | EMPLOYEE(e) AND ( Ǝ s) ( EMPLOYEE(s) AND s.FNAME='Franklin' AND s.LNAME='Wong' AND e.SUPERSSN=s.SSN ) } { qs | ( Ǝ y) ( Ǝ a) ( Ǝ c) ( Ǝ d) ( EMPLOYEE(qrstuvwxyz) AND EMPLOYEE(abcdefghij) AND a='Franklin' AND c='Wong' AND y=d ) }

10 Retrieve the names of employees who work on every project Database System-dww ALL_EMPLOYEE(SSN, PNO)(Rel.A)  (SSN, PNO(WORKS_ON)) ALL_PROJECT(PNO)(Rel.B)  (PNO(PROJECT)) E_ALL_PROJECT  (Rel.A÷Rel.B) RESULT  (FNAME, LNAME (E_ALL_PROJECT * EMPLOYEE)) { e.LNAME, e.FNAME | EMPLOYEE(e) AND ( Ѵ p) ( NOT(PROJECT(p)) OR ( Ǝ w) (WORKS_ON(w) AND p.PNUMBER=w.PNO AND w.ESSN=e.SSN ) ) } { qs | ( Ǝ t) ( EMPLOYEE(qrstuvwxyz) AND ( Ѵ b) ( NOT(PROJECT(abcd)) OR ( Ǝ e) ( Ǝ f) (WORKS_ON(efg) AND e=t AND f=b) ) }

11 Retrieve the names of employees who do not work on any project Database System-dww ALL_EMPLOYEE(SSN)(Rel.A)  (SSN(EMPLOYEE)) ALL_EMPLOYEE_WORKING(SSN)(Rel.B)  (ESSN(WORKS_ON)) E_NOT_WORKING  (Rel.A - Rel.B) RESULT  (FNAME, LNAME ( (EMPLOYEE) SSN=ESSN(E_NOT_WORKING)) { e.LNAME, e.FNAME | EMPLOYEE(e) AND NOT( Ǝ w) ( WORKS_ON(w) AND w.ESSN=e.SSN ) } { qs | ( Ǝ t) ( EMPLOYEE(qrstuvwxyz) AND NOT( Ǝ a) (WORKS_ON(abc) AND a=t ))}

12 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 Database System-dww { e.LNAME, e.FNAME, e.ADDRESS | EMPLOYEE(e) AND ( Ǝ p) ( Ǝ w) (WORKS_ON(w) AND PROJECT(p) AND e.SSN=w.ESSN AND w.PNO=p.PNUMBER AND p.PLOCATION='Houston' AND NOT( Ǝ l) ( DEPT_LOCATIONS(l) AND e.DNO=l.DNUMBER AND l.DLOCATION='Houston' ) ) } { qsv | ( Ǝ t) ( Ǝ z) ( EMPLOYEE(qrstuvwxyz) AND ( Ǝ b) ( Ǝ c) ( Ǝ e) ( Ǝ f) ( WORKS_ON(efg) AND PROJECT(abcd) AND t=e AND f=b AND c='Houston' AND NOT( Ǝ h) NOT( Ǝ i) ( DEPT_LOCATIONS(hi) AND z=h AND i='Houston’ ) ) }

13 List the last names of department managers who have no dependents Database System-dww D_MNG_SSN(Rel.A)  (SSN(DEPARTMENT) E_WITH_DEPENDENT(Rel.A)  (SSN(DPENDENT) MNGR_NO_DEPENDENT  (Rel.A – Rel.B) RESULT  (LNAME(EMPLOYEE * MNGR_NO_DEPENDENT)) { e.LNAME | EMPLOYEE(e) AND ( Ǝ d) ( DEPARTMENT(d) AND e.SSN=d.MGRSSN AND NOT( Ǝ x) (DEPENDENT(x) AND e.SSN=x.ESSN) ) } { s | ( Ǝ t) ( EMPLOYEE(qrstuvwxyz) AND ( Ǝ c) ( DEPARTMENT(abcd) AND t=c AND NOT( Ǝ e) (DEPENDENT(efghi) AND e=t) ) }


Download ppt "Exercise 2 Relational Calculus Database System-dww."

Similar presentations


Ads by Google