Quick answer: Tuple relational calculus (TRC) is a non-procedural query language. A query {t | P(t)} returns every tuple t for which the formula P(t) is true. Formulas are built from atoms (t ∈ R, t.A θ s.B, t.A θ c), the connectives ¬, ∧, ∨ and →, and the quantifiers ∃ and ∀. Only safe expressions, whose results use values from the database or the query, are allowed. Safe TRC, safe domain relational calculus and basic relational algebra have the same expressive power. "For all" queries (division) use ∀, or the equivalent ¬∃ … ¬.
GATE usually shows a TRC expression and asks what it returns, or asks which TRC expression matches an English query or a relational algebra expression. This topic is part of the Relational Algebra and SQL chapter.
General form of a TRC query
- t is a tuple variable that ranges over tuples.
- P(t) is a formula. The result is the set of all tuples t that make P(t) true.
- To return only some attributes, write {t.A, t.B | P(t)}.
Building formulas
Atoms
- t ∈ R: t is a tuple of relation R.
- t.A θ s.B: compares attributes of two tuple variables, where θ is one of =, ≠, <, ≤, >, ≥.
- t.A θ c: compares an attribute with a constant.
Formulas
- Every atom is a formula. If P₁ and P₂ are formulas, so are ¬P₁, P₁ ∧ P₂, P₁ ∨ P₂ and P₁ → P₂.
- ∃s (P(s)) and ∀s (P(s)) are formulas, and s is bound inside them. A variable not bound by a quantifier is free, and only the result variable t should be free.
Useful equivalences
These come straight from predicate logic:
Safe expressions
A TRC expression is safe if every value in its result comes from the constants in the query or the relations it mentions. For example, {t | ¬(t ∈ R)} is unsafe, because infinitely many tuples are not in R. Safe TRC is exactly as expressive as relational algebra.
Relational algebra operations written in TRC
Use Emp(eid, name, sal, dno) and Dept(dno, dname).
| Relational algebra | TRC |
|---|---|
Join example: names of employees who work in the 'Sales' department.
Division ("for all") in TRC
Query: students (sid) enrolled in every course, using Enroll(sid, cid) and Course(cid).
With ∀:
Read it as "the student of t, such that for every course c, there is an enrollment of that student in c".
Without ∀:
Maximum and "more than every" queries
Highest-paid employees:
Employees earning more than everyone in department 5:
Note: if department 5 has no employees, the ∀ condition is vacuously true and every employee qualifies.
Domain relational calculus (DRC) in brief
DRC uses domain variables for single attribute values instead of tuple variables:
Example: names of employees with salary above 50000.
Expressive power
Basic relational algebra, safe TRC and safe DRC are equally expressive (all are relationally complete). SQL is also relationally complete and adds aggregation, grouping and duplicate (bag) semantics.
Summary table
| Pattern | TRC idiom |
|---|---|
| A matching tuple exists (join, semi-join) | |
| No matching tuple (difference) | |
| For all (division) | |
| Maximum | |
| Minimum |
Exam tips
- Pair ∃ with ∧ and ∀ with →. Most wrong options in GATE swap these.
- Read a TRC expression from the inside out, translating each quantifier into English as you go.
- For "maximum" or "minimum", look for a ¬∃ that says "no better tuple exists".
Common mistakes
- Using ∧ inside ∀. ∀s (s ∈ S ∧ P) claims every tuple in the universe is in S.
- Using → inside ∃. ∃s (s ∈ S → P) is true almost trivially, so use ∧.
- Forgetting vacuous truth when the range of ∀ is empty.
- Writing a negation with no positive range such as t ∈ R, which makes the query unsafe.
Practice questions
Q1. What does this return?
Answer: The employees with the minimum salary.
Q2. Is {t | ¬(t ∈ Emp)} a valid query?
Answer: No. It is unsafe, because its result would be infinite.
Q3. Write in TRC: employees who work in a department named 'HR'.
Answer:
FAQs
What is tuple relational calculus?
It is a declarative query language. A query describes the tuples you want, {t | P(t)}, using predicate-logic formulas over relations.
What is a safe expression in relational calculus?
It is an expression whose result uses only values that appear in the database or the query, so the result is always finite.
Is relational calculus more powerful than relational algebra?
No. Safe tuple relational calculus, safe domain relational calculus and basic relational algebra can express exactly the same queries.
How is division written in tuple relational calculus?
With a universal quantifier: for every tuple of the divisor relation, there must be a matching tuple in the dividend.
What is the difference between TRC and DRC?
TRC variables range over whole tuples, while DRC variables range over single attribute values.
Conclusion
Translate English to TRC with the same habits as predicate logic: ∃ with ∧, ∀ with →, and ¬∃ for "no better tuple". Then match TRC and relational algebra using the summary table. Continue with SQL queries, revise relational algebra, or go back to the Relational Algebra and SQL chapter.