Skip to main content

GATE CSE 2014Databases › Relational Algebra & CalculusVerified

GATE CSE 2014 PYQ: Consider the relational schema given below, where eId of the relation dependent is a foreign key referring…

Consider the relational schema given below, where eId of the relation dependent is a foreign key referring to empId of the relation employee. Assume that every employee has at least one associated dependent in the dependent relation.

  • employee (empId, empName, empAge)
  • dependent (depId, eId, depName, depAge)

Consider the following relational algebra query:

ΠempId (employee)−ΠempId (employee⋈(empId=eID)∧(empAge≤depAge)dependent)\Pi_{empId}\:(employee) - \Pi_{empId}\:(employee \bowtie_{(empId=eID) \wedge (empAge \leq depAge)} dependent)

The above query evaluates to the set of empIds of employees whose age is greater than that of

  1. A
    some dependent.
  2. B
    all dependents.
  3. C
    some of his/her dependents.
  4. D
    all of his/her dependents.
    Correct answer

Answer

(D) all of his/her dependents.

Approach

Evaluate the relational algebra expression in two parts: first find employees who have at least one dependent whose age is at least the employee's age, then subtract those employees from all employees.

The inner join selects employees having some dependent with depAge ≥ empAge. Removing their empIds from all employees leaves employees for whom no such dependent exists; because each employee has at least one dependent, this means every dependent has depAge < empAge. Hence the answer is D.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.