Question Details

Consider two relations R(A,B) and S(E,C). A is primary key and E is a FK referring A. Which of the following operations never violate FK constraint?

Options

A

Insert in s

B

Delete from R

C

Insert in R

D

Delete from S

Show Answer

Correct Answer :

Option C

Insert in R

Option D

Delete from S

Solution :

The correct options are Insert in R and Delete from S.

To understand why these operations never violate the Foreign Key (FK) constraint, let us analyze the relationship between the two relations, R(A,B) and S(E,C).

Here, A is the Primary Key (PK) of relation R, and E is a Foreign Key in relation S that references A in relation R. The Foreign Key constraint requires that every value of E in S must either be null (if allowed) or exist as a value of A in R. That is, πE(S)πA(R) (excluding null values).

Let us evaluate each operation to see how it affects this constraint:

1. Insert in R:
When we insert a new tuple into the referenced relation R, we add a new primary key value to A. This expands the set of valid values that the foreign key E can reference. Since it does not remove any existing primary keys, it cannot cause any foreign key in S to point to a non-existent primary key in R. Therefore, inserting into R can never violate the foreign key constraint.

2. Delete from S:
When we delete a tuple from the referencing relation S, we remove a foreign key value E. Since the constraint only requires that existing foreign key values in S must exist in R, removing a row from S simply reduces the referencing set. It cannot create an orphaned reference because we are removing references, not adding them. Therefore, deleting from S can never violate the foreign key constraint.

For completeness, let us look at the other options:
- Insert in S: If we insert a tuple into S with a foreign key value E that does not exist in R, the constraint is violated.
- Delete from R: If we delete a tuple from R whose primary key A is currently being referenced by some tuple's foreign key E in S, the constraint is violated (unless cascade actions are specified).

Unlock Our Free Library

Access expert-curated educational resources and study materials—completely free.

Ask AI Tutor
5 left
Q1 View Question & Options
AI Tutor is solving this question...
Reading question context & options...