Let R1 (A, B, C) and R2 (D, E) be two relation schema, where the primary keys…

2004

Let R1 (A, B, C) and R2 (D, E) be two relation schema, where the primary keys are shown underlined, and let C be a foreign key in R1 referring to R2. Suppose there is no violation of the above referential integrity constraint in the corresponding relation instances r1 and r2. Which one of the following relational algebra expressions would necessarily produce an empty relation ?
GATECS2004

  1. A.

    1

  2. B.

    2

  3. C.

    3

  4. D.

    4

Attempted by 154 students.

Show answer & explanation

Correct answer: B

Key insight: the foreign-key constraint means every value of C in r1 appears as a value of D in r2.

  • From referential integrity: Π_C(r1) ⊆ Π_D(r2).

  • Therefore Π_C(r1) - Π_D(r2) = ∅, because there is no value that is in Π_C(r1) but not in Π_D(r2).

Why the other expressions need not be empty:

  • Π_D(r2) - Π_C(r1) can be non-empty if r2 has D values that no r1 row references.

  • Π_D(r1 ⨝_{C=D} r2) yields the D values that are actually referenced by r1; if r1 has rows, this projection can be non-empty.

  • Π_C(r1 ⨝_{C=D} r2) similarly returns referenced C values and can be non-empty when r1 contains rows.

Final answer: The expression Π_C(r1) - Π_D(r2) necessarily produces the empty relation.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir