The GATE Grind

GATE 2017 CS – Question 51

Databases · Relational Model: Relational Algebra, Tuple Calculus, SQL · 2 marks · Multiple choice

Consider a database that has the relation schemas EMP(EmpId, EmpName, DeptId), and DEPT(DeptName, DeptId). Note that the DeptId can be permitted to be NULL in the relation EMP. Consider the following queries on the database expressed in tuple relational calculus.

(I) $\{t \mid \exists u \in EMP(t[EmpName] = u[EmpName] \wedge \forall v \in DEPT(t[DeptId] \neq v[DeptId]))\}$

(II) $\{t \mid \exists u \in EMP(t[EmpName] = u[EmpName] \wedge \exists v \in DEPT(t[DeptId] \neq v[DeptId]))\}$

(III) $\{t \mid \exists u \in EMP(t[EmpName] = u[EmpName] \wedge \exists v \in DEPT(t[DeptId] = v[DeptId]))\}$

Which of the above queries are safe?

  1. (I) and (II) only
  2. (I) and (III) only
  3. (II) and (III) only
  4. (I), (II) and (III)

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (D) (I), (II) and (III)

Explanation

A tuple calculus expression is safe if every value in its result comes from the values appearing in the relations it uses. In all three queries the result tuple $t$ is built from a tuple of EMP, because $t[EmpName]$ is tied to $u[EmpName]$, and the conditions on $t[DeptId]$ only filter among tuples of the database. This follows the answer in the earlier dataset.