GATE CS 2017 · Set-2 · SQL Queries

NAT · 1 mark · Problem DBMS-SQL-0032

Consider the following tables T1 and T2.\[\begin{array}{cc} \textbf{T1} & \textbf{T2} \\ \begin{array}{|c|c|} \hline P & Q \\ \hline 2 & 2 \\ 3 & 8 \\ 7 & 3 \\ 5 & 8 \\ 6 & 9 \\ 8 & 5 \\ 9 & 8 \\ \hline \end{array} & \begin{array}{|c|c|} \hline R & S \\ \hline 2 & 2 \\ 8 & 3 \\ 3 & 2 \\ 9 & 7 \\ 5 & 7 \\ 7 & 2 \\ \hline \end{array} \end{array}\]In table T1, P is the primary key and Q is the foreign key referencing R in table T2 with on-delete cascade and on-update cascade. In table T2, R is the primary key and S is the foreign key referencing P in table T1 with on-delete set NULL and on-update cascade. In order to delete record (3, 8) from table T1, the number of additional records that need to be deleted from table T1 is

Numerical answer (NAT).

Solve it on GATE DA practice →More Relational Model & SQL problems

Show the worked solution\[\boxed{\text{deleting a T1 row only sets T2.S to NULL; it never deletes a T2 row}}\]Deleting \((3, 8)\) from T1: the T2 rows with \(S = 3\), here \((8, 3)\), get \(S = \text{NULL}\) (on-delete set NULL).No T2 row is deleted, so the cascade from T2 back to T1 (through Q) never fires. No other T1 row is deleted.Answer: 0

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com