Project ForgeSign up free
Database Management Systems
SQL & Transactions
GATE 2017
Hard

Consider tables T1(P,Q) and T2(R,S). In T1, P is the primary key and Q is the foreign key referencing R in T2 with ON DELETE CASCADE and ON UPDATE CASCADE. In T2, R is the primary key and S is the foreign key referencing P in T1 with ON DELETE SET NULL and ON UPDATE CASCADE.

T1 rows (P,Q): (2,2),(3,8),(7,3),(5,8),(6,9),(8,5),(9,8) T2 rows (R,S): (2,2),(8,3),(3,2),(9,7),(5,7),(7,2)

In order to delete record (3,8) from table T1, the number of additional records that need to be deleted from table T1 is ____.

0

Explanation

Deleting T1's row with P=3 only affects rows that reference P=3 via a foreign key — that's T2.S (which references T1.P), specifically T2's row (8,3), whose ON DELETE action is SET NULL, not CASCADE. So that T2 row is merely modified to (8,NULL), not deleted, and this modification doesn't propagate any further (nothing references T2.S). The OTHER foreign-key relationship, T1.Q referencing T2.R, only triggers cascading when a referenced T2.R row is deleted — but no T2 row is being deleted here, only modified. So no additional T1 rows need to be deleted: the answer is 0.

Source: GATE CS 2017 (Session 2) (2017)

This question is part of a 15-day revision cycle — sign in and Project Forge will bring it back the day before you'd forget it.

Start revising free