Relational Algebra Questions with Answers

36 practice questions on Relational Algebra (DBMS) with answers and step-by-step solutions. Try 10 samples below, then practise all 36 free in the AptiNest app.

Sample questions

Question 1Easy

Which relational algebra operator is best suited to answering "find students who have taken ALL courses"?

  1. Natural join
  2. Set difference alone
  3. Union
  4. Division

Answer: D. Division

Explanation

Enrolled(student, course) divided by Courses(course) returns exactly the students paired with every course.

Step-by-step solution

  1. "Taken ALL courses" is a for-all condition.
  2. Division Takes(sid, cid) ÷ Courses(cid) returns sids paired with every cid.
  3. 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 ____.

  1. graphical; procedural
  2. procedural; procedural
  3. procedural; declarative
  4. declarative; procedural

Answer: C. procedural; declarative

Explanation

Algebra specifies a sequence of operations; calculus specifies what the result should satisfy.

Step-by-step solution

  1. Relational algebra says how: a sequence of operations.
  2. Relational calculus says what: a condition on the result.
  3. 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:

  1. σ (sigma)
  2. ρ (rho)
  3. π (pi)
  4. δ (delta)

Answer: B. ρ (rho)

Explanation

ρ_S(R) renames relation R to S, and can also rename its attributes.

Step-by-step solution

  1. Rename is written ρ (rho).
  2. ρ_S(R) renames R to S; it can also rename attributes.
  3. 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?

  1. σ, π, ∪, −, ×, ρ
  2. σ, ∩, ⋈, ÷, ρ
  3. π, ∪, ∩, ⋈
  4. σ, π, ⋈, ∩, ÷

Answer: A. σ, π, ∪, −, ×, ρ

Explanation

Join, intersection and division can all be written using selection, projection, union, difference, product and rename.

Step-by-step solution

  1. The six basic operators are σ, π, ∪, −, x and ρ.
  2. Joins, ∩ and ÷ can be built from them.
  3. 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?

  1. σ_p(R ⋈ S) = σ_p(R) ⋈ S, when p uses only R's attributes
  2. σ_p(R × S) = σ_p(R) × σ_p(S) for any p
  3. R ⋈ S = R × S
  4. π_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

  1. If p uses only R's attributes, rows that fail p can be removed from R before joining.
  2. So σ_p(R ⋈ S) = σ_p(R) ⋈ S.
  3. 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?

  1. 0 and 3
  2. 3 and 5
  3. 3 and 8
  4. 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

  1. Minimum: all 5 S tuples are in R, so 8 − 5 = 3.
  2. 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?

  1. 8 and 13
  2. 5 and 13
  3. 13 and 13
  4. 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

  1. Minimum: all 5 S tuples are also in R: union = 8.
  2. 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?

  1. The count of employees above 50000
  2. Employees earning more than 50000
  3. Only the salary column of all employees
  4. 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

  1. t ranges over tuples of Emp.
  2. The condition keeps tuples with salary > 50000.
  3. 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?

  1. 5
  2. Between 0 and 10
  3. 50
  4. 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

  1. B is the key of S, so each B value appears once in S.
  2. R.B is a NOT NULL foreign key, so every R row matches exactly one S row.
  3. 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
  1. 2
  2. 5
  3. 4
  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

  1. A semijoin keeps each R row that has at least one match, only once.
  2. Rows with B = x (A = 1, 3) and B = y (A = 2, 5) match.
  3. (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 →

Related topics

See all DBMS topics · All topics