CS FundamentalsVery hardGATE CS · Amazon/Microsoft SDE MCQ
P(id PRIMARY KEY) has rows 1, 2. C(id, pid REFERENCES P ON DELETE CASCADE) has (10, 1), (11, 1), (12, 2). G(id, cid REFERENCES C ON DELETE SET NULL) has (100, 10), (101, 10), (102, 11), (103, 12), (104, NULL). After DELETE FROM P WHERE id = 1 (foreign keys enforced), how many rows of G have a NULL cid?
- A. 3
- B. 4
- C. 2
- D. 1
Correct answer: B. 4
Deleting P 1 cascades to C rows 10 and 11. That fires SET NULL in G for 100, 101 and 102, which joins the already-NULL 104: 4 NULLs, and no G row is deleted. Thinking the cascade continues into G would delete rows instead.
More DBMS and SQL questions
- R(A, B, C) is decomposed into R1(A, B) and R2(B, C). Which condition is necessary and sufficient (under FDs only) for the decomposition to…
- R(A, B, C) with FDs A → B and B → C has primary key A. A designer moves to R1(A, B) and R2(B, C). Which statement is correct?
- In a wait-for graph the edges are T1 → T2, T2 → T3, T3 → T1, T3 → T4 and T5 → T2. What is the minimum number of transactions that must be…
- Under basic two-phase locking, which order of serial execution is a schedule conflict equivalent to?
- A query plan computes σ{dept = 'D1' ∧ sal > 50}(Emp ⋈ Dept). Which rewrite is a heuristic optimizer most likely to apply first, and why?
- A B+ tree has order p = 4 (at most 4 children per internal node, at most 3 keys per leaf) and every node except the root is at least half…