Relational Algebra · Databases
31 questions · asked in 19 of 27 years (2000–2026)
MCQ 27 · MSQ 1 · NAT 31-mark 17 · 2-mark 14
2000Questions per year2026
Questions 26–30 of 31
Consider the relation Student (, sex, marks), where the primary key is shown underlined, pertaining to students in a class that has at least one boy and one girl. What does the following relational algebra expression produce? (Note: is the rename operator).
Answer: (D)
The join pairs each student row with a renamed copy of , keeping a pair only if the first student is female, the copy is male, and . So the second part, after , is the set of girls whose marks are at most the marks of some boy.
The whole expression takes all girls and removes those girls. What is left are girls who are not below or equal to any boy, so each has more marks than every boy. Since there is at least one boy, this is meaningful.
Example: boys with 100 and 40, girls with 50 and 30. Each girl is at most the boy with 100, so both are removed and the result is empty. Option (B) would wrongly include the girl with 50, because she has more marks than the boy with 40. Option (C) is the opposite filter (girls who are at least as good as some boy). Option (A) says nothing about boys, so it does not match.
Answer: (D)
The whole expression takes all girls and removes those girls. What is left are girls who are not below or equal to any boy, so each has more marks than every boy. Since there is at least one boy, this is meaningful.
Example: boys with 100 and 40, girls with 50 and 30. Each girl is at most the boy with 100, so both are removed and the result is empty. Option (B) would wrongly include the girl with 50, because she has more marks than the boy with 40. Option (C) is the opposite filter (girls who are at least as good as some boy). Option (A) says nothing about boys, so it does not match.
Answer: (D)
Let R1(,B,(C)) and R2(,E) be two relation schema, where the primary keys are shown underlined, and let C be a foreign key in R1 referring to R2 . Suppose there is no violation of the above referential integrity constraint in the corresponding relation instances r1 and r2 . Which one of the following relational algebra expressions would necessarily produce an empty relation?
Answer: (B)
C in R1 is a foreign key that refers to the primary key D of R2, and there is no violation. So every value in is also a value in :
So is always empty. This is option (B).
The others can be non-empty for some valid instances:
- (A) holds the D values that no R1 tuple refers to. If r2 has a tuple that nobody references (for example, r1 is empty and r2 is not), it is not empty.
- (C) pairs each R1 tuple with every R2 tuple that has a different D. If r1 has a tuple and r2 has two or more tuples, some R2 tuple has a D different from that tuple's C, so the result is not empty.
- (D) gives every C value of r1, because each one has a matching D. It is not empty when r1 has at least one tuple.
Answer: (B)
So is always empty. This is option (B).
The others can be non-empty for some valid instances:
- (A) holds the D values that no R1 tuple refers to. If r2 has a tuple that nobody references (for example, r1 is empty and r2 is not), it is not empty.
- (C) pairs each R1 tuple with every R2 tuple that has a different D. If r1 has a tuple and r2 has two or more tuples, some R2 tuple has a D different from that tuple's C, so the result is not empty.
- (D) gives every C value of r1, because each one has a matching D. It is not empty when r1 has at least one tuple.
Answer: (B)
With regard to the expressive power of the formal relational query languages, which of the following statements is true ?
Answer: (C)
Relational algebra and safe relational calculus have the same expressive power (Codd's theorem): a query can be written in safe relational calculus if and only if it can be written in relational algebra.
Unrestricted relational calculus is more powerful, because it allows unsafe queries. For example has an infinite answer, and relational algebra cannot express it. So (B) is false. (A) is false because algebra cannot express unsafe queries, and (D) is false because (C) is true.
Answer: (C)
Unrestricted relational calculus is more powerful, because it allows unsafe queries. For example has an infinite answer, and relational algebra cannot express it. So (B) is false. (A) is false because algebra cannot express unsafe queries, and (D) is false because (C) is true.
Answer: (C)
Let r and s be two relations over the relation schemes R and S respectively, and let A be an attribute in R. Then the relational algebra expression is always equal to :
Answer: (C)
A is an attribute of , so each tuple of has its value copied from its part. So the selection can be done on before the join:
This holds in every case. Even if also occurs in , the join forces equal values, so the check can still be made on .
(A) is wrong: has only the attributes of and keeps tuples that have no match in .
(B) is wrong: it has no selection and no join with .
Answer: (C)
This holds in every case. Even if also occurs in , the join forces equal values, so the check can still be made on .
(A) is wrong: has only the attributes of and keeps tuples that have no match in .
(B) is wrong: it has no selection and no join with .
Answer: (C)
Suppose the adjacency relation of vertices in a graph is represented in a table Adj(X,Y). Which of the following queries cannot be expressed by a relational algebra expression of constant length ?
Answer: (D)
- (A) A selection on X followed by a projection on Y: . This has a fixed length.
- (B) Select the tuples with and project X: . This has a fixed length.
- (C) A cycle of fewer than three vertices is a self loop (length 1) or a 2-cycle (length 2). A self loop is the same as in (B). For a 2-cycle, join Adj with a copy of itself on and , then project X. This also has a fixed length, and it does not depend on the number of tuples.
- (D) Reachability is the transitive closure of Adj. A path can be as long as the number of vertices, say in a long chain, so we would need that many joins. The query length would grow with the graph, so no expression of constant length can do it.
Answer: (D)
- (B) Select the tuples with and project X: . This has a fixed length.
- (C) A cycle of fewer than three vertices is a self loop (length 1) or a 2-cycle (length 2). A self loop is the same as in (B). For a 2-cycle, join Adj with a copy of itself on and , then project X. This also has a fixed length, and it does not depend on the number of tuples.
- (D) Reachability is the transitive closure of Adj. A path can be as long as the number of vertices, say in a long chain, so we would need that many joins. The query length would grow with the graph, so no expression of constant length can do it.
Answer: (D)
Keep practising
Topics in Databases
ER ModelRelational Schema
Relational AlgebraYou are here
Tuple CalculusSQLIntegrity ConstraintsNormal FormFile SystemTransaction