CS FundamentalsHardGATE CS
Tk(s, c) = (s1, c1), (s1, c2), (s1, c3), (s2, c1), (s2, c2), (s3, c1), (s3, c2), (s3, c3), (s3, c4), (s4, c3), (s5, c2), (s5, c3), (s5, c1), (s5, c3) (note the repeated row for s5) and Cr(c) = (c1), (c2), (c3). How many students does SELECT DISTINCT s FROM Tk t WHERE NOT EXISTS (SELECT * FROM Cr WHERE NOT EXISTS (SELECT * FROM Tk t2 WHERE t2.s = t.s AND t2.c = Cr.c)) return?
- A. 1
- B. 2
- C. 3
- D. 4
Correct answer: C. 3
The double NOT EXISTS is relational division: it returns students taking every course in Cr, here s1, s3 and s5 (3). The shortcut HAVING COUNT(*) = 3 would return only 1 student, because s3 has four rows and s5 has a duplicate row.
More DBMS and SQL questions
- M(s) holds the scores 90, 85, 85, 80, 80, 80, 70, 70, 60. What is the sum over all nine rows of (RANK() OVER (ORDER BY s DESC)…
- A(x) = (3, 5, NULL, 8, 9, 12) and B(x) = (4, NULL, 6). How many rows does SELECT x FROM A WHERE x > ALL (SELECT x FROM B) return? (ALL is…
- R(A, B) has 5000 tuples with V(R, B) = 100 distinct B values. S(B, C) has 3000 tuples with V(S, B) = 300 and V(S, C) = 60. Using the…
- R(A, B, C, D, E, F, G) has the functional dependencies AB -> C, C -> D, D -> E, E -> C, F -> G, BG -> A and AE -> F. How many candidate…
- R(A, B, C, D, E) has the functional dependencies A -> B, BC -> D, D -> E and E -> B. The decomposition R1(A, B), R2(B, C, D), R3(A, D, E) is
- Transactions are T1: R(A) W(A) R(B); T2: W(A) R(B) W(B); T3: R(B) W(A) (each executes its operations in the order shown). Of all possible…