The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+19 votes
2k views

The following table has two attributes $A$ and $C$ where $A$ is the primary key and $C$ is the foreign key referencing $A$ with on-delete cascade.

A C
2 4
3 4
4 3
5 2
7 2
9 5
6 4

The set of all tuples that must be additionally deleted to preserve referential integrity when the tuple $(2, 4)$ is deleted is:

  1. $(3, 4)$ and $(6, 4)$
  2. $(5, 2)$ and $(7, 2)$
  3. $(5, 2), (7, 2)$ and $(9, 5)$
  4. $(3, 4), (4, 3)$ and $(6, 4)$
asked in Databases by Veteran (59.7k points)
edited by | 2k views
+1
@bikram sir pls explain this
how we can apply on -delete cascade in 1 single table ?
+9

 @ set2018 

on -delete cascade in 1 single table means we delete  FK tuples related to PK on that table . 

"A foreign key with cascade delete means that if a record in the parent table is deleted, then the corresponding records in the child table will automatically be deleted."~ this is for multiple tables , in case of single table  we delete FK tuples which related to deleted PK tuple .

A is PK  in this table, A is on-delete cascade.

C is foreign key . We have to maintain Referential Integrity .

tuple (2, 4) is deleted , here 2 is PK ,  and 2 is in FK  in tuples (5,2) and (7,2) so both are deleted .

Now 7 is no where FK . But 5 is FK again in tuple  (9,5) hence tuple (9,5) is also deleted .

overall 3 tuples are deleted  additionally to preserve referential integrity when the tuple (2, 4) is deleted .

+1
simple and grt explanation @Bikram sir !

2 Answers

+30 votes
Best answer

(C)
Since deleting $(2,4)$, since $2$ is a primary key, you have to delete its foreign key occurence i.e $(5,2)$ and $(7,2)$
Since we are delting $5$, and $7$ we have delete it foreign key occurence i.e $(9,5)$.

There is no foreign key occurence for $9$.

answered by Active (3.3k points)
edited by
0
Very good Question and explanation is extremely well

I understand On delete cascade in single Table
+6 votes

here A is behaving like parent and C is  behaving like child bcoz A is PK and C is FK referencing to A.

when (2,4) is deleted then it force to delete all entries in which C contains 2 bcoz there is no 2 remains in parent so child not able to access 2. so delete (5,2) (7,2) which force to delete all entries in which C contains 5or7 bcoz there is no 5 or 7 remain in parent so child not able to access 5 or 7.so delete (9,5) which force to delete all entries in which C contains 9 .

so ans should be C

answered by Active (4.6k points)
0
Nice explanation.Easy to understand on delete cascade  for single table.
Answer:

Related questions



Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

44,467 questions
49,921 answers
165,491 comments
65,899 users