Tuple Relational Calculus (TRC) is a declarative query language for the relational model. It expresses queries as set-builder notation {t | condition} that returns tuples t satisfying the condition. The condition is a formula combining atoms with logical operators like AND and OR. TRC allows safe expressions but cannot perform non-query operations like aggregation or modify the database.
2. What is TRC?
• it is a calculus that was introduced by Edgar F.
Codd as part of the relational model, in order
to provide a declarative database-query
language for this data model.
4. Tuple Relational Calculus
• It is a nonprocedural query language.
• A query is expressed as { t | cond }
• Return all tuples T that satisfy the
condition Cond.
• t is a tuple variable, t[A] denotes the
value of tuple t on attribute A
5. Atoms
• For the construction of the formula we will
assume an infinite set V of tuple variables.
• Examples of atoms are:
• (t.age = s.age) — t has an age attribute
and s has an age attribute with the same
value
• (t.name = “priyank”) — tuple t has a name
attribute and its value is ”Priyank"
• Book(t) — tuple t is present in relation
Book.
6. Formulas
• Formulas are combined using operators ∧
(and), ∨ (or) and ¬ (not), and we can use the
existential quantifier (∃) and the universal
quantifier (∀) .
• Here ∃ and ∀ quantifier are called bound
variable..
7. Predicate Calculus Formula
• Set of comparison operatores:
<, ≤, >, ≥ , = , ≠
• Set of connectives:
and ( ^), or (v), not (¬)
• Implication (=>):
x => y means: if x is true, then y is true.
8. Predicate Calculus Formula
(cont’d)
• ∃ t ∈ r ( Q(t) ) ≡ There exists a tuple t
in relation r such that predicate Q (t)
is true
• ∀ t ∈ r ( Q(t) ) ≡ Q is true for all
tuples t in relation r
9. Formal semantics
• " f1 ∧ f2 " is true if and only if " f1 " is true and
" f2 " is true,
• " f1 ∨ f2 " is true if and only if " f1 " is true or
" f2 " is true or both are true,
• " ¬ f " is true if and only if " f " is not true,
10. Example
• student(rollNo, name, degree, year,
sex, deptNo, advisor)
• department(deptId, name, hod, phone)
Question:
Obtain the rollNo, name of all girl
students in the Maths Dept (deptNo=
2)
11. • Answer
• {s.rollNo,s.name| student(s)^ s.sex=‘F’^
s.deptNo=2}
• Here student(s) is true whenever value of s is
a tuple in the student relation,
• false otherwise
21. Safety of Expressions
• It is possible to write tuple calculus
expressions that generate infinite
relations.
• For example, expression
{ t | ¬ t ∈ r } results in an infinite relation
if the domain of any attribute of relation
r is infinite.
22. To solve this problem
• We restrict the set of allowable
expressions to safe expressions.
• What is safe expression?
23. Definition of Safe Expression
• An expression { t | P(t) } in the tuple
relational calculus is safe if every
component of t appears in one of
the relations, tuples, or constants
that appear in tuple relational
formula P.
24. Example
• { t | ¬ ( t ∈loan) } is NOT safe.
It is possible to have a tuple t not in
loan that contains values that do not
appear in loan.
• All examples in the previous
expressions are safe.
25. Limitations of TRC
• It can not express queries involving
aggregations,closure.
• It can not express non-query operations like
insert,delete,update.
• because those involve modeling the changes
in the state of a database.
26. Summary
• The relational calculus provides an
• alternate way to express queries
• • A formal model based on logical formulae
and set theory
• Equivalence with algebra means can use
• either or both – but only one for formal
• proofs