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

Let $R_1 \left(\underline{A}, B, C\right)$ and $R_2\left(\underline{D}, E \right) $ be two relation schema, where the primary keys are shown underlined, and let C be a foreign key in $R_1$ referring to $R_2$. Suppose there is no violation of the above referential integrity constraint in the corresponding relation instances $r_1$ and $r_2$. Which of the following relational algebra expressions would necessarily produce an empty relation?

  1. $\Pi_D (r_2) - \Pi_C (r_1)$

  2. $\Pi_C (r_1) - \Pi_D (r_2)$

  3. $\Pi_D \left(r_1 \bowtie_{C \neq  D}r_2\right)$

  4. $\Pi_C \left(r_1 \bowtie_{C = D}r_2\right)$

asked in Databases by Veteran (59.6k points) | 1.5k views
0
What if the field 'C' of relation R1 has NULLs  for some of the records (I believe FKs can have NULLs). Will option B always return empty set?
0

1 Answer

+23 votes
Best answer

Answer is (B).

$C$ in $R1$ is a foreign key referring to the primary key $D$ in $R2$. So, every element of $C$ must come from some $D$ element.

answered by Active (5k points)
edited by
0
Why not A?
+3
because we can add values in D , that wont violate the referential integrity constraints..

so there can be a case when there are extra elements in D that are not  there in C therefore option A will  be wrong.
0
how can we assume that C refers to D and not E in r2, it says referential integrity not foreign key constraint....
0

If C has NULL in it then the query projection (r1) - projection (r2) will be a set containing null which isn't empty set . Hence the answer would be wrong.

+1
Child-parent=GAME OVER


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

40,772 questions
47,479 answers
145,671 comments
62,241 users