Let and be two relations in which is the foreign key of that refers to the primary key of . Consider the following four operations and
-
Insert into
-
Insert into
-
Delete from
-
Delete from
Which of the following can cause violation of the referential integrity constraint above?
View worked solution
Answer: B
A referential integrity constraint requires that any value of a foreign key in a referencing relation must exist as a primary key value in the referenced relation.
Here, is the referencing relation (with foreign key ) and is the referenced relation (with primary key, say, ). Thus, for every tuple in , the value of must exist in the primary key column of .
Let's analyze the four operations:
- I. Insert into : Safe. Adding a new primary key value to does not affect any existing references in .
- II. Insert into : Can cause a violation. If we insert a tuple into with a foreign key value that does not exist in , the referential integrity is violated.
- III. Delete from : Can cause a violation. If we delete a tuple from whose primary key is currently referenced by one or more tuples in , those tuples in will be left with dangling references.
- IV. Delete from : Safe. Removing a tuple from the referencing relation never creates any dangling references.
Therefore, only operations II and III can cause a violation of the referential integrity constraint.
Free practice · Your answers on this page are not saved.
