CS FundamentalsHardGATE CS (PYQ pattern)
Tables: P(id); C(id, p) with p referencing P(id) ON DELETE CASCADE; G(id, c) with c referencing C(id) ON DELETE SET NULL. Rows: P = {1, 2}; C = (10,1), (11,1), (12,2); G = (100,10), (101,10), (102,11), (103,12). After DELETE FROM P WHERE id = 1, how many rows remain in C and in G, and how many G rows have c = NULL?
- A. C: 1 row, G: 1 row, 0 with NULL
- B. C: 1 row, G: 4 rows, 3 with NULL
- C. C: 3 rows, G: 4 rows, 0 with NULL
- D. C: 1 row, G: 2 rows, 1 with NULL
Correct answer: B. C: 1 row, G: 4 rows, 3 with NULL
Deleting P(1) cascades to C rows 10 and 11, leaving only (12,2). Deleting those C rows triggers the SET NULL action on G: rows 100, 101, 102 keep existing but get c = NULL; row 103 is unchanged. So G keeps all 4 rows, 3 with NULL.
More DBMS and SQL questions
- Optimistic concurrency control with backward validation. Transactions (start, validation, finish times; read set; write set): T1 (0, 4, 5…
- A two-phase commit has 1 coordinator and 5 participants and uses the read-only optimisation. All 5 receive PREPARE. Three vote YES, one…
- A linear hashing file starts with 2 buckets (hash h0 = k mod 2, then h1 = k mod 4, h2 = k mod 8, ...), a bucket holds 2 keys before it…
- A B+ tree index is built on (a, b) in this order. For which of these predicates can a search descend directly to a contiguous range of…
- Which of the following relational-algebra identities are valid for union-compatible relations R and S? I. σ{A=1}(R ∪ S) = σ{A=1}(R) ∪…
- R(A, B) has 100 tuples; R.B is a foreign key to S(B), which is S's primary key, but R.B allows NULL and 10 tuples of R have B = NULL. S…