Skip to main content

GATE CSE 2017Databases › Relational Algebra & CalculusVerified

GATE CSE 2017 PYQ: Consider a database that has the relation schemas EMP(EmpId, EmpName, DeptId), and DEPT(DeptName, DeptId).…

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.

  1. {tt | ∃\existsu ∈\in EMP(t[EmpName] = u[EmpName] ∧\wedge ∀\forallv ∈\in DEPT(t[DeptId] ≠\neq v[DeptId]))}
  2. {tt | ∃\existsu ∈\in EMP(t[EmpName] = u[EmpName] ∧\wedge ∃\existsv ∈\in DEPT(t[DeptId] ≠\neq v[DeptId]))}
  3. {tt | ∃\existsu ∈\in EMP(t[EmpName] = u[EmpName] ∧\wedge ∃\existsv ∈\in DEPT(t[DeptId] == v[DeptId]))}

Which of the above queries are safe?

  1. A
    I and II only
  2. B
    I and III only
  3. C
    II and III only
  4. D
    I, II and III
    Correct answer

Answer

(D) I, II and III

Approach

A tuple relational calculus query is safe if it yields a finite result and all values in the result belong to the finite active domain (values present in the database or constants in the query). Since every variable in these queries is bound to either EMP or DEPT (both finite relations), and the free variable t is constrained only by comparisons with those bound variables, no query can produce tuples with values outside the finite database domain. Thus all three queries are safe.

Under the standard definition of safety in tuple relational calculus, a query is safe if all its variables are bound to finite relations or constants. Here, u is bound to EMP, v is bound to DEPT, and t is constrained by them. Thus the result of each query is a finite subset of the database domain. Therefore all three queries I, II, and III are safe, making option D correct.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.