CS FundamentalsVery hardProduct-company MCQ pattern
Table Enroll(sid, cid) rows: (1, 'C1'), (1, 'C2'), (2, 'C1'), (3, 'C1'), (3, 'C2'), (3, 'C3'), (4, 'C3'). Table Course(cid) rows: ('C1'), ('C2'), ('C3'). What does this query return?
Table Enroll(sid, cid) rows: (1, 'C1'), (1, 'C2'), (2, 'C1'), (3, 'C1'), (3, 'C2'), (3, 'C3'), (4, 'C3').
Table Course(cid) rows: ('C1'), ('C2'), ('C3').
What does this query return?
SELECT DISTINCT sid FROM Enroll e
WHERE NOT EXISTS (
SELECT * FROM Course c
WHERE NOT EXISTS (
SELECT * FROM Enroll x
WHERE x.sid = e.sid AND x.cid = c.cid));- A. 1, 2, 3 and 4
- B. 1 and 3
- C. No rows
- D. 3
Correct answer: D. 3
This double NOT EXISTS is relational division: students for whom there is no course they have not taken, i.e. students enrolled in ALL courses. Only student 3 has C1, C2 and C3; student 1 lacks C3.
More DBMS and SQL questions
- R(A, B, C, D, E) has FDs A → B, B → C, C → A, D → E. How many candidate keys does R have, and what is its highest normal form?
- R(A, B, C, D, E, F) has FDs AB → C, C → D, D → B, E → F. Which statement is correct?
- R(A, B, C, D) has FDs AB → CD, C → A, D → B. How many candidate keys does R have, and what is its highest normal form?
- R(A, B, C, D) has FDs AB → CD, C → A, D → B, giving candidate keys AB, AD, BC and CD. How many superkeys does R have?
- R(A, B, C) with AB → C and C → B is decomposed into R1(A, C) and R2(B, C) to reach BCNF. Which statement is correct?
- Schedule: R2(A), R1(B), W2(A), R3(A), W1(B), W3(A), R2(B), W2(B). Which statement is correct?