Consider the following three relations in a relational database. Employee(eId…
2022
Consider the following three relations in a relational database.
Employee(eId , Name ), Brand (bId , bName ), Own( eId ,bId )
Which of the following relational algebra expressions return the set of eIds who own all the brands?
- A.
πeId (πeld,bId(Own) / πbId (Brand))
- B.
πeId(Own) – πeId((πeId(Own) × πbId(Brand)) – πeId, bId(Own))
- C.
πeId (πeId, bId(Own) / πbId(Own))
- D.
πeId((πeId(Own) × πbId(Own) / πbId(Brand))
Attempted by 102 students.
Show answer & explanation
Correct answer: A, B
Key idea: Use relational division to find the employee identifiers that are associated with every brand identifier.
Correct expression explained:
Project the pairs (eId, bId) from Own: (π eId,bId (Own)).
Project the set of all brand ids from Brand: (π bId (Brand)).
Divide the Own pairs by the Brand ids: (π eId,bId (Own)) ÷ (π bId (Brand)). Division returns those eId values that appear paired with every bId in the divisor.
Finally project eId from the division result: π eId ( (π eId,bId (Own)) ÷ (π bId (Brand)) ).
Why this works:
An employee identifier appears in the division result only if for every brand id in the Brand relation there is a matching pair in Own. That means the employee owns every brand.
Alternative (equivalent) formulation:
You can express the same result without the division operator by:
1) Form all possible pairs of eId and brand id: (π eId (Own) × π bId (Brand)).
2) Remove the pairs that actually exist in Own to get missing pairs: (π eId (Own) × π bId (Brand)) – (π eId,bId (Own)).
3) Project the eIds that are missing at least one brand and subtract them from all eIds to obtain those owning every brand.
Common mistakes to avoid:
Using the set of brand ids projected from Own as the divisor instead of projecting from Brand. That only enforces ownership of brands that appear in Own, not necessarily all brands defined in Brand.
Formulas that are syntactically malformed or that fail to form the correct divisor (the full set of brand ids) will not yield the intended set of employees.
A video solution is available for this question — log in and enroll to watch it.