-- part2a SELECTDISTINCT E.ename, E.age FROM Emp E WHERE E.eid IN ( SELECT W.eid FROM Works W JOIN Dept D ON W.did = D.did WHERE D.dname ='Hardware' ) AND E.eid IN ( SELECT W.eid FROM Works W JOIN Dept D ON W.did = D.did WHERE D.dname ='Software' );
-- part2b SELECT E.ename FROM Emp E WHERE E.salary > ( SELECTMAX(D.budget) FROM Works W JOIN Dept D ON W.did = D.did WHERE W.eid = E.eid );
-- part2c SELECT E.ename, E.age FROM Emp E WHERE E.eid IN ( SELECT managerid FROM Dept WHERE budget >1000000 ) AND E.eid NOTIN ( SELECT managerid FROM Dept WHERE budget <=1000000 );
-- part2d SELECT E.ename FROM Emp E JOIN Dept D ON E.eid = D.managerid WHERE D.budget = ( SELECTMAX(budget) FROM Dept );
-- part2e SELECT W.did, COUNT(DISTINCT W.eid) AS employee_count FROM Works W GROUPBY W.did HAVINGSUM(W.pct_time) >=2000;
Part 3: Design Theory (25 points)
Relation schema R(A1,A2,A3,A4) satisfies the functional dependencies (FDs):
A3→A1
A4→A2
A1,A2→A3
A1,A2→A4
1. List all candidate keys of R. (6 points)
Compute attribute closures:
{A1,A2}+={A1,A2,A3,A4} (by FD3 and FD4)
{A1,A4}+={A1,A4,A2} (by FD2), then {A1,A2}+={A1,A2,A3,A4} (by FD3 and FD4)
{A2,A3}+={A2,A3,A1} (by FD1), then {A1,A2}+={A1,A2,A3,A4} (by FD3 and FD4)
{A3,A4}+={A3,A4,A1,A2} (by FD1 and FD2)
2. The main requirement of BCNF is that the left-hand side of an FD must be a superkey. Do the above FDs violate this requirement? Explain each one. (6 points)
BCNF requires: for every non-trivial FD X→Y, X must be a superkey.
FD1 A3→A1: A3 is not a superkey (A3+={A1,A3}, does not contain all attributes). Violates BCNF.
FD2 A4→A2: A4 is not a superkey (A4+={A2,A4}, does not contain all attributes). Violates BCNF.
FD3 A1,A2→A3: {A1,A2} is a candidate key (superkey). Does not violate BCNF.
FD4 A1,A2→A4: {A1,A2} is a candidate key (superkey). Does not violate BCNF.
3. The secondary requirement of 3NF is that for an FD X→Y, Y must be part of a candidate key. Do the above FDs violate this requirement? Explain each one. (4 points)
FD1 A3→A1: A3 is not a superkey, but A1 is a prime attribute (contained in candidate keys {A1,A2} and {A1,A4}). Does not violate 3NF.
FD2 A4→A2: A4 is not a superkey, but A2 is a prime attribute (contained in candidate keys {A1,A2} and {A2,A3}). Does not violate 3NF.
FD3 A1,A2→A3: A1,A2 is a superkey. Does not violate 3NF.
FD4 A1,A2→A4: A1,A2 is a superkey. Does not violate 3NF.
All FDs satisfy the 3NF requirement; no violations.
4. Provide a lossless BCNF decomposition of R with the minimum number of tables. (9 points)
Since FD1 and FD2 violate BCNF, decomposition is needed. The minimum number of tables is 3 (because the dependencies cannot satisfy BCNF with only 2 tables). Here is a lossless join decomposition: