IAE Academy

GATE DA

The relational model

Relational algebra and tuple calculus

The relational model stores data as relations (sets of tuples) identified by keys. Relational algebra (procedural) and tuple relational calculus (declarative) are two formal languages for querying them, and their safe forms express exactly the same queries. GATE DA questions on this topic ask you to evaluate an expression on small tables and count the result tuples, to pick the expression that answers a stated query, and to judge which calculus expressions are safe, so these notes concentrate on exact operator rules, equivalences and cardinality bounds.

5 previous-year questions · 5 solved · 6 practice questions

Relations, tuples and keys

A relation schema names the attributes; a relation instance is a finite set of tuples, each giving one value per attribute. Because a relation is a set, there is no tuple order and no duplicate tuple. The degree is the number of attributes and the cardinality is the number of tuples.

Convention used in these notes. Relational algebra and tuple calculus use set semantics: no result ever contains a duplicate tuple. SQL uses bag semantics: SELECT keeps duplicates unless DISTINCT is written, while UNION, INTERSECT and EXCEPT remove duplicates unless ALL is written. Wherever NULL appears, any comparison involving it is unknown (three-valued logic), and a selection or join condition that is unknown does not select the tuple, as in a SQL WHERE clause. SQL keywords are written in capitals.

Term

Meaning

Superkey

A set of attributes such that no two distinct tuples agree on all of (in every legal instance)

Candidate key

A minimal superkey: removing any attribute breaks uniqueness

Primary key

The one candidate key chosen to identify tuples; its attributes cannot be NULL

Alternate key

A candidate key that was not chosen as primary

Prime attribute

An attribute that belongs to at least one candidate key

Foreign key

A set of attributes of whose value in every tuple is either NULL or equal to the value of a candidate key (usually the primary key) in some tuple of the referenced relation

SUPERKEY CONDITION

Every superset of a superkey (within the attributes of ) is a superkey, so under set semantics the set of all attributes is always a superkey. Candidate keys are the minimal superkeys.

COUNTING SUPERKEYS

is the number of attributes of . A superkey is any attribute set that contains at least one candidate key. With two keys, inclusion-exclusion subtracts the sets counted twice: those containing .

EXAM TIP

Keys are a property of the schema (they must hold for every legal instance), not of one instance. A small table can show that a set is not a key (two rows agree), but it can never prove that a set is a key.

Basic relational algebra operators

Every operator takes relations and returns a relation (the algebra is closed), so expressions nest. The basic operators are selection , projection and rename (unary), and union , set difference and Cartesian product (binary). Theta and natural joins, intersection and division can all be written using these six. Rename only changes names, so is often called the complete set.

SELECTION

Keeps whole tuples satisfying the condition; schema unchanged; .

PROJECTION

Keeps the listed columns and removes duplicate rows (set semantics). For non-empty , , with whenever the list contains a superkey.

CARTESIAN PRODUCT

Pairs every tuple of with every tuple of . Clashing attribute names are qualified (, ) or renamed with .

UNION AND SET DIFFERENCE

Defined only for union-compatible relations: the same degree, with the -th attributes of both having the same domain. By convention the result takes its attribute names from the first operand. Union is commutative and associative; difference is neither.

RENAME

Gives the result the relation name and attribute names ; needed for self-joins.

CARDINALITY BOUNDS FOR SET OPERATIONS

Set semantics, and union-compatible. Also and . The upper bounds of and are reached when ; their lower bounds when the smaller relation is contained in the larger.

EXAM TIP

Projection and union remove duplicates, so a count taken after or can be smaller than you expect. Always list the distinct rows before counting.

Joins, intersection and division

Theta join, natural join, intersection and division are derived operators: each can be rewritten with the basic ones, and they exist because they shorten common queries. Outer joins, at the end of this section, are an extension: they also need NULL to pad the missing side.

THETA JOIN

. An equi-join is a theta join whose condition is only equalities; it keeps both copies of the compared attributes.

NATURAL JOIN

are the attributes with the same name in both relations, and the result has degree . With no common attribute it equals ; when the two schemas are identical it equals . A NULL never matches, not even another NULL. Natural join is commutative and associative (up to column order).

INTERSECTION

Union-compatible relations; .

DIVISION

and , where the attributes of are a proper subset of those of and is the rest. The result has schema (degree ): the -values that appear in paired with every tuple of . If is empty, the formula gives .

DIVISION SIZE BOUNDS

Each -value in the result needs its own tuples in , one for each tuple of , and these tuples are different for different -values.

Outer joins keep tuples that find no partner, padding the missing side with NULL. Write (left outer), (right outer) and (full outer); the superscripts name the kind of join, not a relation. The left outer join keeps every tuple of the left relation, the right keeps every tuple of the right, and the full outer join keeps both.

OUTER JOIN COUNTS

is the inner (natural) join; and are the numbers of tuples of and of that match no tuple of the other relation. Left outer adds only , right outer only .

NATURAL JOIN SIZE BOUNDS

If the common attributes form a key of , each tuple of matches at most one tuple of , so . If they are also a foreign key of referencing with no NULL in it, the size is exactly .

WORKED EXAMPLE

Let and . Find .

Solution
  1. .

  2. has tuples: every with and .

  3. Subtract (6 tuples). The tuples left are the pairs that lacks: and .

  4. Project on : . These -values are missing at least one from .

  5. . Check: only and appear with both and .

Answer: , two tuples.

EXAM TIP

To read a division quickly, group by and ask which groups contain every -value. A group may contain extra -values and still qualify: extras do no harm, only gaps do.

Equivalences and standard query patterns

Two expressions are equivalent when they return the same relation on every legal instance. One counter-example instance is enough to show that two expressions are not equivalent.

Equivalence

Condition

Always

(otherwise the left side is undefined)

uses only attributes in

(also for )

uses only attributes of

, and likewise for and

Always; also

Always

and

Equality can fail (example below)

and

Natural join, up to column order

and are commutative and associative

is neither: and in general

WORKED EXAMPLE

Show that projection does not distribute over set difference or intersection, using and .

Solution
  1. , so .

  2. . The two sides differ.

  3. , so .

  4. . The two sides differ again.

Answer: Both equalities fail on this instance, so neither is a valid rewrite. Only the one-way inclusions in the table hold.

LARGEST VALUE WITHOUT AGGREGATION

is a renamed copy of . The subtracted part is every -value that some other value of exceeds, so what remains is the maximum value of . Use in place of for the minimum. This assumes contains no NULL.

EXAM TIP

To decide whether two expressions are equivalent, first try a tiny instance (one or two tuples per relation, sharing a value so the operators interact). A counter-example settles a no; a yes needs an argument that works for every instance.

Evaluating expressions and counting tuples

Procedure for a counting question

  1. Write the schema and the tuples of every base relation as a small list.

  2. Evaluate from the innermost bracket outwards, writing out each intermediate relation in full.

  3. For a join, match on the common attributes (or on the stated condition) and list each matching pair; do not guess from sizes.

  4. After any projection or union, delete duplicate rows (set semantics).

  5. For outer joins, add the unmatched tuples with NULL padding last.

  6. Count only at the end, and cross-check with the bounds above.

WORKED EXAMPLE

and . How many tuples are in , , , and ?

Solution
  1. Join on : meets ; meets and ; meets and ; and have no partner.

  2. : 5 tuples.

  3. : are all distinct: 5 tuples.

  4. : : duplicates collapse, 3 tuples.

  5. Left outer adds the unmatched tuple as : .

  6. Full outer also adds the unmatched tuple as : .

Answer: 5, 5, 3, 6 and 7 tuples respectively.

EXAM TIP

A selection such as returns nothing, because a comparison with NULL is unknown. Testing for NULL needs IS NULL in SQL, which has no plain equivalent in the basic algebra above.

Tuple relational calculus and safety

Tuple relational calculus (TRC) is declarative: it describes what the answer tuples satisfy, not how to compute them. An expression is , where is a tuple variable and is a formula.

TRC EXPRESSION

The result is the set of all tuples for which formula is true. is the only free variable of ; every other tuple variable must be bound by a quantifier.

Building blocks of a formula

  1. Atoms: (range of ), and with and a constant. abbreviates .

  2. Connectives: , and implication .

  3. Quantifiers: and ; both bind .

  4. Duality: and .

Reading the table. The answer tuple has the schema of the algebra result in the same row, and , , may each be a list of attributes. For , and , and are union-compatible. In the product row has schema and has schema ; in the natural-join row and ; in the division row and .

Algebra

Tuple calculus

An expression is safe if it is guaranteed to return a finite set: every value in an answer tuple must come from the relations named in the expression or from the constants written in it, and quantified variables range only over such values. is unsafe: over an unbounded domain, infinitely many tuples are not in . is safe when and are union-compatible. Safe tuple calculus and basic relational algebra express exactly the same queries; a query language that can express all of them is called relationally complete. Neither can express aggregation (such as counting tuples), ordering, or recursion such as transitive closure.

EXAM TIP

To spot an unsafe expression, check every disjunct separately. In each one, every attribute of the answer variable must be pinned down positively: by , or by equality with a constant or with a variable that ranges over a relation. (only compared), (only negated) and (second disjunct unbounded) are all unsafe.

Translating between calculus, algebra and SQL

Each algebra shape has a standard SQL form. A selection-projection-join query is SELECT-FROM-WHERE. Difference becomes EXCEPT or a correlated NOT EXISTS; intersection becomes INTERSECT or EXISTS; division becomes a double NOT EXISTS. NOT IN expresses difference only when the subquery returns no NULL: if it returns one, x NOT IN (...) is never true (it is false or unknown), so the query returns no rows.

The algebra query with and is, in SQL (DISTINCT matches the set semantics of the algebra):

SELECT DISTINCT R.A
FROM R
JOIN S
ON R.B = S.B
WHERE S.C > 5;

Division for and reads as: an A such that there is no B of S that fails to appear with it in R. If S is empty, the query returns every A of R, which agrees with .

SELECT DISTINCT r.A
FROM R r
WHERE NOT EXISTS (
  SELECT *
  FROM S s
  WHERE NOT EXISTS (
    SELECT *
    FROM R r2
    WHERE r2.A = r.A
    AND r2.B = s.B
  )
);

Algebra idea

SQL form

Calculus form

Difference

EXCEPT or NOT EXISTS

Intersection

INTERSECT or EXISTS

Division

double NOT EXISTS

inside

Natural join

NATURAL JOIN or JOIN ... ON

with equal common attributes

Outer join

LEFT, RIGHT, FULL OUTER JOIN

no direct form: it needs tuples padded with NULL

EXAM TIP

When a question says every, all or never, think division or difference: for all is , which is , which is a double NOT EXISTS. An inner join alone can only say there exists.

PREVIOUS-YEAR QUESTIONS

5 questions from the DA papers

Try each question first, then open the answer. We placed each question under a topic ourselves; the exam paper does not label topics.

See these papers in full: GATE DA 2026 · GATE DA 2025 · GATE DA 2024

GATE 2026 DA Q.42

GATE 2026 · DAQ.42 · 2 marks · MCQ

Consider the given relations , and . The relation has three columns , and . The relation has three columns , and . The relation has two columns and .

Relation : (P1, Q1, R1), (P2, Q2, R2), (P3, Q3, R2).

Relation : (P1, Q1, 2), (P1, Q2, 5), (P2, Q1, 6), (P3, Q3, 1).

Relation : (P1, T1), (P3, T2), (P4, T3), (P4, NULL).

Consider the relational algebra expression

where denotes natural join operation.

Which of the following options is the correct output for the given expression?

GATE 2026 DA question 42: Three small tables side by side.Tap to open full size
Figure from the GATE 2026 DA paper. It is part of the question.
Figure description

Three small tables side by side. X(P,Q,R): rows (P1,Q1,R1), (P2,Q2,R2), (P3,Q3,R2). Y(P,Q,S): rows (P1,Q1,2), (P1,Q2,5), (P2,Q1,6), (P3,Q3,1). Z(P,T): rows (P1,T1), (P3,T2), (P4,T3), (P4,NULL).

  1. (A)

    Two rows (P1, R1, 2) and (P1, R1, 5)

  2. (B)

    Three rows (P1, R1, 2), (P1, R1, 5) and (P2, R2, 6)

  3. (C)

    One row (P1, R1, 2)

  4. (D)

    Zero rows

Answer and solution
GATE 2026 DA Q.42: answer and solution

GATE 2026 DA Q.59

GATE 2026 · DAQ.59 · 2 marks · NAT

Let there be two relations and as shown. has three columns , and . has two columns and .

Relation X (columns P, Q, R): (P1, Q1, R1), (P2, Q2, R2), (P3, Q3, R2).

Relation Y (columns P, S): (P1, 10), (P1, 15), (P2, 20), (P3, 1).

Consider that the following tuple relational calculus expression is evaluated.

The number of tuples that will be returned is ______. (Answer in integer)

GATE 2026 DA question 59: Two tables side by side.Tap to open full size
Figure from the GATE 2026 DA paper. It is part of the question.
Figure description

Two tables side by side. X has header P, Q, R and rows (P1, Q1, R1), (P2, Q2, R2), (P3, Q3, R2). Y has header P, S and rows (P1, 10), (P1, 15), (P2, 20), (P3, 1).

Answer and solution
GATE 2026 DA Q.59: answer and solution

GATE 2025 DA Q.17

GATE 2025 · DAQ.17 · 1 mark · MCQ

Consider the following three relations:

Car (model, year, serial, color)
Make (maker, model)
Own (owner, serial)

A tuple in Car represents a specific car of a given model, made in a given year, with a serial number and a color. A tuple in Make specifies that a maker company makes cars of a certain model. A tuple in Own specifies that an owner owns the car with a given serial number. Keys are underlined; (owner, serial) together form key for Own. (⋈ denotes natural join)

Which one of the following options describes what the above expression computes?

  1. (A)

    All owners of a red car, a car made by ABC, or a red car made by ABC

  2. (B)

    All owners of more than one car, where at least one car is red and made by ABC

  3. (C)

    All owners of a red car made by ABC

  4. (D)

    All red cars made by ABC

Answer and solution
See the question in the paper
GATE 2025 DA Q.17: answer and solution

GATE 2025 DA Q.62

GATE 2025 · DAQ.62 · 2 marks · NAT

Consider the following tables, Loan and Borrower, of a bank.

Query: where denotes natural join.

The number of tuples returned by the above relational algebra query is ______ (Answer in integer)

GATE 2025 DA question 62: Two tables.Tap to open full size
Figure from the GATE 2025 DA paper. It is part of the question.
Figure description

Two tables. Loan(loan_num, branch_name, amount): (L11, Banjara Hills, 90000), (L14, Kondapur, 50000), (L15, SR Nagar, 40000), (L22, SR Nagar, 25000), (L23, Balanagar, 80000), (L25, Kondapur, 70000), (L19, SR Nagar, 65000). Borrower(customer_name, loan_num): (Anand, L11), (Karteek, L11), (Karteek, L14), (Ankita, L15), (Gopal, L19), (Karteek, L22), (Karteek, L23), (Sunil, L23), (Sunil, L25).

Answer and solution
GATE 2025 DA Q.62: answer and solution

GATE 2024 DA Q.26

GATE 2024 · DAQ.26 · 1 mark · MCQ

Consider a database that includes the following relations:

Defender(name, rating, side, goals)
Forward(name, rating, assists, goals)
Team(name, club, price)

Which ONE of the following relational algebra expressions checks that every name occurring in Team appears in either Defender or Forward, where denotes the empty set?

  1. (A)

  2. (B)

  3. (C)

  4. (D)

Answer and solution
See the question in the paper
GATE 2024 DA Q.26: answer and solution

PRACTICE

6 questions to test yourself

PRACTICE 12 marks · NAT

Relation and relation . Under set semantics, how many tuples does the full outer join on the common attribute contain?

Answer and solution

Answer:

  1. Matching on : and each meet , giving 2 tuples.

  2. meets and , giving 2 more, so .

  3. Unmatched in : and , since has no . So .

  4. Unmatched in : , since has no . So .

  5. Full outer join size .

PRACTICE 22 marks · MSQ

Let record that employee works on project , and let list all projects; is non-empty. Which expressions return exactly the employees who work on every project in , as a relation with schema ?

  1. (A)

  2. (B)

  3. (C)

  4. (D)

Answer and solution

Answer: (A), (B)

  1. A is the definition of division with and : the -values paired in with every tuple of . Correct.

  2. B is the expansion of division: lists every possible (employee, project) pair, subtracting leaves the missing pairs, and removing those employees leaves exactly the ones with no gap. Correct.

  3. C returns employees who work on at least one project that is in , not necessarily all of them. Wrong.

  4. D is a Cartesian product with schema , not a set of employees. Wrong.

PRACTICE 31 mark · MCQ

has 6 tuples and has 4 tuples. Under set semantics, let . What are the minimum and maximum possible values of , in that order?

  1. (A)

    2 and 10

  2. (B)

    6 and 10

  3. (C)

    0 and 10

  4. (D)

    2 and 6

Answer and solution

Answer: (A)

  1. Let , so .

  2. , hence .

  3. At , (maximum). At , (minimum, when ).

  4. So the range is 2 to 10.

PRACTICE 41 mark · MCQ

Which of the following tuple relational calculus expressions is NOT safe? Here and are relations with the same single attribute , and in every option the answer tuple has the single attribute .

  1. (A)

  2. (B)

  3. (C)

  4. (D)

Answer and solution

Answer: (B)

  1. A restricts to tuples of , so the answer is a subset of a finite relation. Safe.

  2. B asks for every tuple not in , and there are infinitely many such tuples over an unbounded domain. Unsafe.

  3. C fixes the only attribute of to an -value that occurs in . Safe.

  4. D is the union of two finite relations, and each disjunct bounds . Safe.

PRACTICE 51 mark · NAT

A relation has exactly two candidate keys, and . How many distinct non-empty attribute sets are superkeys of ?

Answer and solution

Answer:

  1. A superkey is any set that contains a candidate key.

  2. Sets containing : , which is 4 sets.

  3. Sets containing but not : only , which is 1 set.

  4. Total . Check with the formula: .

PRACTICE 61 mark · MCQ

Let and be union-compatible relations with schema . Under set semantics, which equivalence does NOT hold for every instance?

  1. (A)

  2. (B)

  3. (C)

  4. (D)

Answer and solution

Answer: (C)

  1. A holds: a tuple with is in exactly when it is in , so both sides are the tuples of with that are not in .

  2. B holds: every -value of comes from a tuple of or of , and conversely.

  3. C fails: with and , the left side is but the right side is .

  4. D holds: cascading selections is the same as selecting on the conjunction.

OFFICIAL GATE 2027 SYLLABUS WORDING

Copied from the GATE 2027 syllabus; see all 2027 syllabi.

GATE DA

relational model: relational algebra, tuple calculus

Preparing in Kolkata? IAE Academy's course for GATE DA.