in Databases edited by
13,657 views
52 votes
52 votes

Consider the following tables $T1$ and $T2.$

$$\overset{T1}{\begin{array}{|c|c|c|} \hline \textbf {P} & \textbf {Q} \\\hline  \text {2} &  \text{2 }\\\hline \text{3} & \text{8} \\\hline \text{7} & \text{3} \\\hline \text{5} & \text{8} \\\hline  \text{6 } &\text{9} \\\hline \text{8} & \text{5} \\\hline \text{9} & \text{8} \\\hline \end{array}}
\qquad \overset{T2}{\begin{array}{|c|c|c|} \hline \textbf {R} & \textbf {S} \\\hline  \text {2} &  \text{2 }\\\hline \text{8} & \text{3} \\\hline \text{3} & \text{2} \\\hline \text{9} & \text{7} \\\hline  \text{5 } &\text{7} \\\hline \text{7} & \text{2}  \\\hline \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 $\langle 3, 8 \rangle$ from the table $T1,$ the number of additional records that need to be deleted from table $T1$ is _______

in Databases edited by
by
13.7k views

4 Comments

If you analyze clearly NO tuple will be deleted from T2 in any case untill we want to delete.[ since t2 has on delete set null]

2
2

Only thing to be known is On Delete Cascade / On Delete Set Null  apply to tables i.e here On-Delete Cascade is on T1 and On Delete Set Null is on T2

that means tuple wont be deleted from T2 ,instead the corresponding value of attribute which violate referential integrity will be set to Null ​​​​​​.

Rest is simple if concept of ODC and ODSN is clear.

7
7
consider the table
0
0

6 Answers

82 votes
82 votes
Best answer

As Q refers to R so, deleting $8$ from Q won't be an issue, however S refers P. But as the relationship given is on delete set NULL, $3$ will be deleted from $T1$ and the entry in $T2$ having $3$ in column S will be set to NULL. So, no more deletions. Answer is 0.

edited by

4 Comments

@prateekkmr60 @just_bhavana

What if question is delete < 3,2 > from Table T2, as it is not mention for table T2 on-delete set NULL .

It takes additional 1 delete in T1 i.e. <  7,3>   and

0 delete in T2 but  2 cell to  set Null in Column S.

Am I right ?

0
0
In case of on delete cascade,i believe yes.

on deletion of 3,8 no effect on Q-> R reference. though for S->P , now all entries in S which have entry 3 should be removed. this leads to removal of 8 from R which affects the Q->R reference. Hence all entries in R which have 8 would be deleted. which leads to removal of 5 and 9 from P. This will have impact on S via S->R reference. However there are no 5 and 9 entries in S. So over all 5,8 and 9,8 get deleted from T1 as a result of the 3,8 deletion.
0
0
given that on DELETE, set Null to dependents of T1, cascade to dependents of T2.
1
1
46 votes
46 votes

Answer is 0. 

3 Comments

Good explanation

I miss the term On delete set null

and I get 2 answer

but I read the question again and  I'm done the silly mistake to read a question

I get 0 is answer
1
1
Can anyone explain why the answer would be 2 if S is referencing P with on delete cascade instead of on delete set null???? any records from T2 would be deleted???

Is it because when deleting (5,8) record 5 is being searched in T2's S but since there's no 5 available no record would be deleted in T2.

same for record (9,8).
0
0
Answer correct, but on delete set null is applicable to T1 and on delete cascade on T2 not vice versa
1
1
14 votes
14 votes

On-delete set NULL would set 3 in table T2 under S column as NULL. That's it. No record needs to be deleted off of T1.
Ans: 0


However, if On-delete-cascade was the situation, < 8, 3> would be deleted from T2, which would in turn result in the deletion of  < 5, 8 > and < 9,8 > from T1.

Answer would have been 2 in this case.


PS: 'On delete set null' would make the row < 8,3 > as < 8, NULL> and not <NULL, NULL>


 

0 votes
0 votes

For T1 table if any violation occurred then we need to that Field as NULL. So we no need to delete any thing from T1 table.

So  Number of Deletions required in T1 Table = 0                  

Answer:

Related questions