Let R1 (a, b, c) and R2 (x, y, z) be two relations in which a is the foreign…
2018
Let R1 (a, b, c) and R2 (x, y, z) be two relations in which a is the foreign key of R1 that refers to the primary key of R2 . Consider following four options.
(a) Insert into R1 (b) Insert into R2
(c) Delete from R1 (d) Delete from R2
Which of the following is correct about the referential integrity constraint with respect to above ?
- A.
Operations (a) and (b) will cause violation.
- B.
Operations (b) and (c) will cause violation.
- C.
Operations (c) and (d) will cause violation.
- D.
Operations (d) and (a) will cause violation.
Attempted by 741 students.
Show answer & explanation
Correct answer: D
Answer: Delete from R2 and Insert into R1 will cause referential integrity violations.
Insert into R1: May cause a violation if the inserted foreign key value (attribute a in R1) has no matching primary key value in R2. Referential integrity requires every foreign key value to reference an existing parent key.
Insert into R2: Does not cause a referential integrity violation; adding a parent row only increases the set of valid referenced keys.
Delete from R1: Does not cause a violation because removing child rows cannot create dangling references; it only removes references to parent rows.
Delete from R2: Can cause a violation if there exist rows in R1 that reference the deleted parent row, leaving dangling foreign keys unless referential actions (such as ON DELETE CASCADE or SET NULL) are specified.
Therefore, the operations that can cause referential integrity violations are inserting into the child relation (Insert into R1) and deleting from the parent relation (Delete from R2).
A video solution is available for this question — log in and enroll to watch it.