Database Systems · Relational Calculus
Introduction to Relational Calculus: Tuple vs Domain Relational Calculus
Overview
Relational calculus is one of the two categories of formal query languages of the relational model, the other being relational algebra.
It is a theoretical language, split into tuple relational calculus and domain relational calculus, and it is not typed directly into a real database system — practical queries are written in an RDBMS language such as SQL.
Key concepts
- Formal query languages: the query languages of the relational model are divided into two categories — relational algebra and relational calculus.
- Relational calculus: a formal (theoretical) query language, further divided into exactly two types:
- Tuple Relational Calculus (TRC)
- Domain Relational Calculus (DRC)
- Formal / theoretical language: both relational algebra and relational calculus are theoretical languages which do not exist practically; they are not the languages actually typed into a real database system.
- Practical query language: to implement a query on a practical database, a real query language provided by an RDBMS, such as SQL, must be used instead.
- Theoretical foundation: these formal languages serve as the theoretical foundation used when designing and implementing practical query languages.
How it works
- The formal languages of the relational model are divided into two categories — relational algebra and relational calculus.
- Relational calculus itself is of two types — tuple relational calculus and domain relational calculus.
- Both relational algebra and relational calculus are formal languages, i.e. theoretical languages which do not exist practically.
- To implement a query on a practical database, the query cannot be written in relational algebra or relational calculus; a real query language provided by an RDBMS, such as SQL, must be used.
Comparison
| Basis | Relational Algebra | Relational Calculus |
|---|---|---|
| Category of formal language | One of the two formal-language categories | The other formal-language category |
| Sub-types | — (single language) | Tuple relational calculus, Domain relational calculus |
| Nature | Formal / theoretical language | Formal / theoretical language |
| Practically usable? | No — not directly implemented in real systems | No — not directly implemented in real systems |
| Used in practice as | Theoretical basis only | Theoretical basis only |
| Actual implementation language | SQL (in an RDBMS) | SQL (in an RDBMS) |
Revision summary
- Formal query languages = relational algebra + relational calculus.
- Relational calculus has exactly two types: tuple relational calculus and domain relational calculus.
- Both algebra and calculus are theoretical — they are not practically existing languages.
- Neither relational algebra nor relational calculus can be written directly on a real database.
- Real queries require an RDBMS query language such as SQL.
- These formal languages are the theoretical foundation for designing and implementing practical query languages.
Previous-year exam insights
- Relational algebra is procedural (it specifies a sequence of operations to compute the result), whereas relational calculus is non-procedural/declarative (it only specifies what the result must satisfy, not how to compute it).
- Relational algebra and relational calculus are equivalent in expressive power: every query expressible in relational algebra can be expressed in tuple or domain relational calculus and vice versa (they are relationally complete).
- Tuple relational calculus uses tuple variables ranging over relations, with formulas like { t | t ∈ R ∧ P(t) }, and the result is a set of tuples; domain relational calculus uses domain variables ranging over attribute values, with formulas like { <x, y> | ∃z (R(x, z) ∧ ...) }, and the result is a set of value tuples.
- In relational calculus, the quantifiers used are ∃ (there exists) and ∀ (for all), and logical connectives ∧ (and), ∨ (or), ¬ (not) combine predicates; a query is written as { variable(s) | predicate }.
- A safe relational calculus expression must have a finite result: without a safety condition, expressions such as { t | ¬(t ∈ R) } can produce an infinite set, so only safe expressions are allowed.
- SQL is based on relational calculus (its declarative SELECT-FROM-WHERE form), while relational algebra corresponds to the procedural evaluation plan; both are relationally complete and SQL includes them.