Let and be relational schemes such that and Now consider the following queries on the database:
-
Select R.a,R.b From R,S Where R.c = S.c
Which of the above queries are equivalent?
View worked solution
Answer: A
Given the relational schemas and , we have . Let and be relations over and respectively.
1. Analysis of Query 1
The expression is given as:
Since and , the combined set of attributes is exactly . Thus, . Substituting this back, we get:
This is the standard relational algebra formulation for the Division operator (). It returns all tuples that pair with every tuple in to form a valid tuple in .
2. Analysis of Query 2
The Tuple Relational Calculus (TRC) expression is:
This states that for a tuple to be in the result:
- must belong to .
- For every tuple , there must exist a tuple such that the -attributes of match () and the -attributes of match ().
Since , this means the combined tuple must exist in for every . This is the exact definition of the division operator ().
Thus, Query 1 and Query 2 are equivalent.
3. Analysis of Queries 3 and 4
- Query 3: The universal quantifier applies to all tuples in , which does not represent the division operation.
- Query 4: The SQL query performs an inner join on the common attribute and projects the attributes and . This is equivalent to , which is not equivalent to division.
Therefore, only queries 1 and 2 are equivalent.
Free practice · Your answers on this page are not saved.
