Tuple relational calculus
The tuple relational calculus: tuple variables ranging over relations, atoms and formulas with connectives and the quantifiers there exists and for all, free and bound variables, queries of the form { t | P(t) }, translating every relational algebra operator (selection, projection, union, difference, product, join, division) into calculus, queries with negation and universal quantification, safe versus unsafe expressions, and the equivalence of safe calculus with relational algebra.
Why it exists
Relational algebra says how to compute an answer (a sequence of operators). The relational calculus says what the answer is: a logical condition that the tuples of the answer must satisfy. SQL is based on this declarative idea. GATE asks: what does this calculus expression return, write a query in calculus, which expressions are safe, translate between algebra and calculus.
Prerequisites
You need relational algebra (relational algebra) and first-order logic with quantifiers (the logic course).
Precise definitions
A tuple variable takes tuples as values. The range of a variable is given by an atom or .
Atoms:
- (or ): is a tuple of relation ;
- or , where and is a constant.
Formulas are built from atoms with and the quantifiers ("there is a tuple such that ") and ("for every tuple , "). The rule : . The quantifiers are related by .
A variable is bound if a quantifier introduces it, otherwise free. A query has the form
where is the only free variable of the formula . The answer is the set of all tuples for which is true. To keep the answer finite the formula must be safe (see below).
How it works
Reading calculus queries
The four queries run on the sample database (their answers were computed by evaluating the formula tuple by tuple, and each was compared with the SQL query on a real engine):
Queries in tuple relational calculus: start
Computed, not typed| sid | sname | dept | age |
|---|---|---|---|
| 1 | Asha | CS | 20 |
| 3 | Chen | CS | 21 |
| 5 | Esha | CS | 23 |
| 8 | Hari | CS | 20 |
Step 0
The simplest form: t ranges over Student and the condition selects. This is the selection σ dept='CS' (Student). The answer is every tuple t that makes the formula true.
- : a plain selection.
- : the result tuple has a single attribute
sname; the quantified variables stand for the joined tuples. - : negation of an existential quantifier gives "no such tuple".
- : the universal quantifier expresses "for all courses taught by instructor 10, the student is enrolled" (the part is the implication "if is taught by 10 then ...").
Algebra to calculus
Every operator of relational algebra has a calculus counterpart (each was checked by evaluating the formula for all candidate tuples over a small domain and comparing with the operator):
| algebra | tuple calculus |
|---|---|
| (each attribute of equals the matching attribute of or ) | |
Differences in style: calculus has no order of operations, no intermediate relations and expresses "not" and "for all" directly; algebra needs set difference and division for them.
Safety
Consider . If has two tuples, the answer is "every possible tuple except those two": its size depends on how many values the attributes may take. With values from the answer has tuples:
An unsafe calculus expression: start
Computed by a script, not typed| domain | tuples satisfying { t | ¬(t ∈ R) } | k² − |R| |
|---|---|---|
| domain of 3 values | ||
| domain of 4 values | ||
| domain of 5 values | ||
| domain of 6 values |
Step 0
R has 2 tuples. The expression { t | ¬(t ∈ R) } asks for all tuples that are not in R; their number depends on the (unbounded) domain. Safe expressions only produce values that appear in the database.
An expression is safe if it produces only tuples whose values come from the database (or the query), so the answer is finite and does not depend on the domain. Typical unsafe expressions: a lone negation , a disjunction in which the two branches do not restrict the same variables, a free variable that is not bounded by a positive range atom. The practical rule: every free variable and every quantified variable must be bounded by a positive atom .
Codd's theorem (quoted): the relational algebra and the safe tuple relational calculus have the same expressive power. Equivalent statements: every algebra query can be written as a safe calculus formula (the table above), and every safe calculus formula can be translated to algebra (with product, selection, projection, difference and division as needed). A language with this power is called relationally complete; SQL is relationally complete (and stronger: it has aggregates and arithmetic).
The domain relational calculus
In the domain calculus variables range over attribute values instead of tuples: . It is equivalent in power to the tuple calculus (restricted to safe expressions). It is treated, together with safety, in domain calculus and safety.
Worked examples
EX 1Read an expression
Easy: the courses with more than three credits (C1 and C5 in the sample database). It is .
EX 2Free and bound variables
EasyIn the variable is free (it is the answer), is bound by . The answer consists of the students that have at least one enrolment.
EX 3Translate a sentence
MediumNames of students enrolled in no course of the CS department. . In algebra this needs a set difference between all student names and the names of those with a CS enrolment.
EX 4Universal quantifier from existential
Medium. Query 4 above can therefore be written with two nested negations: "there is no course of instructor 10 for which the student has no enrolment". This is the double NOT EXISTS pattern of SQL.
EX 5Typical questions
GATE level(a) "Which expression is unsafe?" One that can return infinitely many tuples, for example or without a range for . (b) "What does express?" A division-like 'for all' query. (c) "The calculus and the algebra are:" equivalent in power (for safe expressions). (d) "Calculus is procedural or declarative?" Declarative. (e) "Which quantifier gives 'there exists at least one'?" . (f) "What is the result of ?" The projection .
Cheat box
Cheat box
- Query ; is the only free variable; answer = tuples satisfying .
- ; .
- = range atom + condition; = and equalities; = ; = ; = two ; = with implication.
- Safe expression: every variable bounded by a positive range atom; unsafe: , unbounded disjunction.
- Codd: safe TRC relational algebra.
Traps and GATE patterns
Connections
Builds on
Across subjects
No cross-subject links yet.
SQL queries with EXISTS, NOT EXISTS and IN are calculus in disguise (nested queries, SQL basics); the algebra is the operational counterpart (relational algebra).
PYQs
9 previous year questions from your book. I re-solved each one myself (2 by running or simulating, 7 by reasoning only); the book's key is shown next to my answer. All PYQs
Consider a relational database schema with two
relations R(P, Q) and S(X, Y)
Let E= {⟨u⟩|∃v∃w⟨u, v⟩∈R∧⟨v, w⟩∈S} be a
tuple relational calculus expression.
Which one of the following relational algebraic
expressions is equivalent to E ?- (a)ΠP(R⋈R.P=S.XS)
- (b)ΠP(S⋈S.X=R.QR)
- (c)ΠP(R⋈R.P=S.YS)
- (d)ΠP(S⋈S.Y=R.QR)
Consider two relations describing teams and players in a sports league: teams (tid,tname): tid, tname are team-id and team-name, respectively.players(pid, pname,tid): pid, pname, and tid denote player-id, playername and the team-id of the player, respectively. Which ONE of the following tuple relational calculus queries returns the name of the players who play for the team having name as 'MI'?
- (a){ p. pname | p∈players∧∃t (t∈teams∧p.tid = t.tid∧t.tname = 'MI')
- (b){ p. pname | p∈teams∧∃t (t∈players∧p.tid = t.tid∧t.tname ='MI')}
- (c){ p. pname | p∈players∧∃t (t∈teams∧t.tname = 'MI')}
- (d){ p. pname | p∈teams∧∃t (t∈players∧t.tname = 'MI')}
Consider a database that has the relation schemas
EMP(Empld,
EmpName,
Deptld)
and
DEPT(DeptName, Deptld). Note that the Deptldcan be
permitted to a NULL in the relation EMP. Consider the
following queries on the database expressed in tuple
relational calculus.
(I) {t|∃u ε EMP(t[EmpName) = u[EmpName] Λ ∀
∨ε DEPT(t[Deptld] ≠ V[Deptld]))}
(II) {t|∃u ε EMP(t[EmpName) = u[EmpName] Λ ∃∨ ε
DEPT(t[Deptld] ≠V[Deptld]))}
(III) {t|∃u ε EMP(t[EmpNmae) = u[EmpName] Λ ∃∨ ε
DEPT(t[Deptld] =V[Deptld]))}
Which of the above queries are safe?- (a)I and II only
- (b)I and III only
- (c)II and III only
- (d)I, II and III.
Consider the following relation schema
Students(rollno:integer, sname: string)
Courses(courseno:integer,cname: string)
Registration (rollno: integer, courseno: integer, percent:
real)
Which of the following queries are equivalent to this query
in English?
"Find the distinct names of all students who score more
than 90% in the course numbered 107".
(I) SELECT DISTINCT S.sname
FROM Students as S, Registration as R
WHERE R.rollno = S. rollno AND R.courseno = 107 AND
R.percent> 90
(II) πsname(σcourseno= 107 Λ percent> 90 (Registration ⋈Students))
(III) {T|∃S ε Students, ∃R ε Registration (S.rollno =
R.rollno Λ R.courseno = 107 Λ R.percent> 90 Λ T.sname
= S.sname)}
(IV) {<SN>|∃SR∃RP(<SR,SN>∈Students∧<SR,107,RP>∈
Registration∧ RP>90)}- (a)I, II, III and IV
- (b)I, II and III only
- (c)I, II and IV only
- (d)II, III and IV only
Let R and S be relational schemes such that R = {a, b,
c} and S = {c}. Now consider the following queries on
the database:
1 πR-S(r) -πR-S(πR-S(r) × s-πR-S,S(r))
2. {t|t∈πR-S(r) ∧∀u∈s(∃v∈r(u= v[S] ∧t=
v[R-S]))}
3. {t|t∈πR-S(r) ∧∀v∈r(∃u∈s(u= v[S] ∧t=
v[R-S]))}
4. Select R.a, R.b
From R, S
Where R.c = S.c
Which of the above queries are equivalent?- (a)1 and 2
- (b)1 and 3
- (c)2 and 4
- (d)3 and 4
Which of the following tuple relational calculus expression(s) is/are equivalent to ∀t ∈ r (P(t))? I. ¬∃t ∈ r (P(t)) II. ∃t ∉ r (P(t)) III. ¬∃t ∈ r (¬P(t)) IV. ∃t ∉ r (¬P(t))
- (a)I only
- (b)II only
- (c)III only
- (d)III and IV only
Consider the following relational schema:
• Student(school-id, sch-roll-no, sname, saddress)
• School(school-id, sch-name, sch-address, sch-phone)
• Enrolment(school-id, sch-roll-no, erollno, examname)
• ExamResult(erollno, examname, marks)
Consider the following tuple relational calculus query.
DATABASE MANAGEMENT SYSTEM
{ t | ∃E ∈ Enrolment ( t = E.school-id ∧
|{ x | x ∈ Enrolment ∧x.school-id = t ∧
(∃B ∈ExamResult ( B.erollno =
x.erollno∧B.examname = x.examname∧B.marks> 35 ))
}| ÷ |{ x | x ∈ Enrolment ∧x.school-id = t }| * 100 > 35
) }
If a student needs to score more than 35 marks to pass
an exam, what does the query return?- (a)The empty set
- (b)schools with more than 35% of its students enrolled in some exam or the other
- (c)Schools with a pass percentage above 35% over all exams taken together
- (d)schools with a pass percentage above 35% over each exam
Consider the relation employee(name, sex,
supervisorName) with name as the key.
supervisorName gives the name of the supervisor of the
employee under consideration. What does the following
Tuple Relational Calculus query produce?
{e.name | employee(e) ∧ }
(∀x) [ ¬employee(x) ∨x.supervisorName ≠ e.name
∨x.sex = "male" ] }- (a)Names of employees with a male supervisor.
- (b)Names of employees with no immediate male subordinates.
- (c)Names of employees with no immediate female subordinates.
- (d)Names of employees with a female supervisor.
Which of the following relational query languages have the same expressive power? 1. Relational algebra 2. Tuple relational calculus restricted to safe Expressions 3. Domain relational calculus restricted to safe expressions
- (a)II and III only
- (b)I and II only
- (c)I and III only
- (d)I, II and III
Self-check
Question 1
What does return?
Show answerHide
The tuples of whose -value does not occur in : minus the tuples that match on (an anti-join).
Question 2
Why is unsafe?
Show answerHide
It denotes all tuples not in ; there are infinitely many (or as many as the domain allows), so the answer is not determined by the database.
Question 3
Which quantifier pattern expresses relational division?
Show answerHide
: for every tuple of the divisor there is a matching tuple in the dividend.
Question 4
Is the tuple relational calculus procedural?
Show answerHide
No, it is declarative: it states what the answer must satisfy, not how to compute it.
Revision card
One-screen revision
- with free ; atoms , ; , .
- ; = .
- Algebra operators map to calculus formulas; division uses .
- Safe = bounded by positive range atoms; Codd's theorem: safe calculus = algebra.
References
- ·Silberschatz, Korth, Sudarshan, Database System Concepts (7th edition), the section on the tuple relational calculus (in recent editions it is an online or appendix chapter; older editions have it in Chapter 3 or 6)
- ·Elmasri, Navathe, Fundamentals of Database Systems (7th edition), Section 8.6 (the tuple relational calculus)
Verification
scripts/enum-checks/db_sqlcheck.py: the calculus translation of every relational algebra operator on this page (selection, projection, union, difference, product, natural join, division) was evaluated by its semantics, namely testing the formula for every candidate tuple over the finite domain {1, 2, 3}, and equals the result of the corresponding operator of scripts/db_lib.py on 300 random relations; the four example queries were evaluated by iterating over the tuples of the sample database and agree with the SQL queries run on SQLite; for the unsafe expression { t | not (t in R) } the number of satisfying tuples over a domain of k values was computed for k = 3 to 6 and equals k^2 - |R|. Codd's theorem (safe calculus and relational algebra have the same expressive power) is a textbook theorem, quoted and not machine-proved. Textbook chapter references are from memory and differ between editions. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and re-derived against the textbook definitions and the sample database. DEFECT FOUND AND FIXED: a forward reference to a page that is now built was turned into a link. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)