Sample questions
Question 1Easy
Which relational algebra operator is best suited to answering "find students who have taken ALL courses"?
- Natural join
- Set difference alone
- Union
- Division
Answer: D. Division
Explanation
Enrolled(student, course) divided by Courses(course) returns exactly the students paired with every course.
Step-by-step solution
- "Taken ALL courses" is a for-all condition.
- Division Takes(sid, cid) ÷ Courses(cid) returns sids paired with every cid.
- So division is the natural operator.
Why the other options are wrong
- A. A natural join finds students with at least one course, not all.
- B. Division can be built from difference, product and projection, but difference alone is not enough.
- C. Union just combines relations.
Tip: "ALL" in the question = division.
Question 2Easy
Relational algebra is a ____ query language, while relational calculus is ____.
- graphical; procedural
- procedural; procedural
- procedural; declarative
- declarative; procedural
Answer: C. procedural; declarative
Explanation
Algebra specifies a sequence of operations; calculus specifies what the result should satisfy.
Step-by-step solution
- Relational algebra says how: a sequence of operations.
- Relational calculus says what: a condition on the result.
- So algebra is procedural, calculus is declarative.
Why the other options are wrong
- A. QBE is graphical; algebra is not.
- B. Calculus states conditions, not steps.
- D. This is reversed.
Tip: Algebra = how; calculus = what.
Question 3Easy
The rename operator in relational algebra is denoted by:
- σ (sigma)
- ρ (rho)
- π (pi)
- δ (delta)
Answer: B. ρ (rho)
Explanation
ρ_S(R) renames relation R to S, and can also rename its attributes.
Step-by-step solution
- Rename is written ρ (rho).
- ρ_S(R) renames R to S; it can also rename attributes.
- It is needed for self-joins.
Why the other options are wrong
- A. σ is selection.
- C. π is projection.
- D. δ is used for duplicate elimination in extended (bag) algebra, not rename.
Tip: ρ = rename, needed for self-joins.
Question 4Easy
Which set of operators is a complete (minimal) set for relational algebra?
- σ, π, ∪, −, ×, ρ
- σ, ∩, ⋈, ÷, ρ
- π, ∪, ∩, ⋈
- σ, π, ⋈, ∩, ÷
Answer: A. σ, π, ∪, −, ×, ρ
Explanation
Join, intersection and division can all be written using selection, projection, union, difference, product and rename.
Step-by-step solution
- The six basic operators are σ, π, ∪, −, x and ρ.
- Joins, ∩ and ÷ can be built from them.
- So option A is the complete basic set.
Why the other options are wrong
- B. It lacks projection, union and difference.
- C. It lacks selection and difference.
- D. It lacks union and difference.
Tip: Basic six: σ π ∪ − x ρ.
Question 5Medium
Which pushdown rewrite is generally valid and helps query performance?
- σ_p(R ⋈ S) = σ_p(R) ⋈ S, when p uses only R's attributes
- σ_p(R × S) = σ_p(R) × σ_p(S) for any p
- R ⋈ S = R × S
- π_A(R − S) = π_A(R) − π_A(S), for any attribute list A of R and S
Answer: A. σ_p(R ⋈ S) = σ_p(R) ⋈ S, when p uses only R's attributes
Explanation
Selections can be pushed to the relation whose attributes they mention, shrinking the join input. Projection does not distribute over difference in general.
Step-by-step solution
- If p uses only R's attributes, rows that fail p can be removed from R before joining.
- So σ_p(R ⋈ S) = σ_p(R) ⋈ S.
- Joining fewer rows is faster.
Why the other options are wrong
- B. If p uses only R's attributes, it cannot be applied to S.
- C. A natural join is not a product when there are common attributes.
- D. Projection does not distribute over difference.
Tip: Push selections down, close to the tables.
Question 6Medium
Union-compatible relations R and S have 8 and 5 tuples. What are the minimum and maximum sizes of the difference R − S?
- 0 and 3
- 3 and 5
- 3 and 8
- 0 and 8
Answer: C. 3 and 8
Explanation
- At most all 5 tuples of S are removed from R (leaving 3);
- if they share nothing, all 8 remain.
Step-by-step solution
- Minimum: all 5 S tuples are in R, so 8 − 5 = 3.
- Maximum: no overlap, so all 8 R tuples remain.
Why the other options are wrong
- A. At most 5 R tuples can be removed, so at least 3 remain.
- B. With no overlap all 8 remain.
- D. S can remove at most 5 tuples.
Tip: Difference: |R| − min(|R|, |S|) to |R|.
Question 7Medium
Union-compatible relations R and S have 8 and 5 tuples. What are the minimum and maximum sizes of their union R ∪ S?
- 8 and 13
- 5 and 13
- 13 and 13
- 0 and 13
Answer: A. 8 and 13
Explanation
The union is smallest when S is contained in R (8 tuples) and largest when they are disjoint (8 + 5 = 13).
Step-by-step solution
- Minimum: all 5 S tuples are also in R: union = 8.
- Maximum: no overlap: 8 + 5 = 13.
Why the other options are wrong
- B. The union always contains all 8 R tuples.
- C. Overlap can reduce the union to 8.
- D. A union can never be smaller than either input.
Tip: Union: max(|R|, |S|) to |R| + |S|.
Question 8Medium
In tuple relational calculus, what does {t | t ∈ Emp ∧ t.salary > 50000} return?
- The count of employees above 50000
- Employees earning more than 50000
- Only the salary column of all employees
- Employees earning at most 50000
Answer: B. Employees earning more than 50000
Explanation
The result contains whole tuples t from Emp that satisfy the condition, like σ_salary > 50000(Emp).
Step-by-step solution
- t ranges over tuples of Emp.
- The condition keeps tuples with salary > 50000.
- Whole tuples are returned: employees earning more than 50000.
Why the other options are wrong
- A. Calculus returns tuples, not counts.
- C. The whole tuple t is returned, not one column.
- D. The condition is > 50000.
Tip: {t | condition} = all tuples meeting the condition.
Question 9Hard
R(A, B) has 10 tuples and S(B, C) has 5 tuples, B is the primary key of S, and R.B is a foreign key to S.B with NOT NULL. How many tuples does R ⋈ S have?
- 5
- Between 0 and 10
- 50
- 10
Answer: D. 10
Explanation
Each R tuple matches exactly one S tuple (the referenced key exists and is unique), so the join has exactly as many tuples as R.
Step-by-step solution
- B is the key of S, so each B value appears once in S.
- R.B is a NOT NULL foreign key, so every R row matches exactly one S row.
- Result = |R| = 10.
Why the other options are wrong
- A. Several R rows may reference the same S row.
- B. The constraints guarantee exactly one match per R row.
- C. Each R row matches only one S row.
Tip: FK (NOT NULL) to PK join: size = child table size.
Question 10Hard
The semijoin R ⋉ S returns the tuples of R that join with at least one tuple of S. How many tuples does it return for the relations below?
R: A B
1 x
2 y
3 x
4 z
5 y
S: B C
x 10
y 20
y 30
y 40
v 50
- 2
- 5
- 4
- 8
Answer: C. 4
Explanation
R-tuples whose B value appears in S (x or y): (1, x), (2, y), (3, x), (5, y). Each R-tuple appears once, so 4.
Step-by-step solution
- A semijoin keeps each R row that has at least one match, only once.
- Rows with B = x (A = 1, 3) and B = y (A = 2, 5) match.
- (4, z) has no match.
Result: 4 rows.
Why the other options are wrong
- A. 2 counts distinct matching B values.
- B. 5 includes the unmatched z row.
- D. 8 is the full join, which repeats rows for each match.
Tip: Semijoin = WHERE EXISTS; never more rows than R.
Practise all 36 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →