Database Systems · Relational Algebra
Relational Algebra vs Relational Calculus Overview
Overview
Relational algebra and relational calculus are the two basic theoretical languages, or sets of operations, used on the relational model before SQL. Understanding how they work on the relational model builds the foundation for designing and using SQL on an RDBMS. They are different from each other, and SQL is derived as a combination of the two.
Key concepts
- Relational algebra and relational calculus: two basic theoretical languages, or two basic sets of operations, applied to the relational model before SQL.
- Table as a set: in these languages a table is viewed as a set, and the operations are the set operations possible on that relation.
- Complementary viewpoints: the two approaches form a pair of complementary viewpoints — algorithm and implementation, conceptual and reality, theory and practical.
- Relational algebra: requires specifying both what is wanted and how to get it.
- Relational calculus: requires specifying only what is wanted, without specifying how to get it.
- SQL: derived as a combination of relational algebra and relational calculus.
- GATE importance: relational algebra is more important than relational calculus for GATE, although both are studied.
Drawing the diagram…
How it works
- Before moving to SQL, relational algebra and relational calculus are introduced as the foundational operation sets for the relational model.
- The relational model is treated as a set of tuples/relations, so the operations studied are set-based operations.
- The two languages are then contrasted by their specification style: algebra gives what and how, calculus gives what only.
- SQL is understood as a combination of both languages.
Comparison
| Aspect | Relational Algebra | Relational Calculus |
|---|---|---|
| Specification | Specifies both what we want and how we want it | Specifies only what we want, not how we want it |
| Nature | Theoretical language / set of operations on the relational model | Theoretical language / set of operations on the relational model |
| View of data | Table is viewed as a set; operations are set operations | Table is viewed as a set; operations are set operations |
| Role in the pair | The algorithm / implementation / practical side of the contrast | The conceptual / theory side of the contrast |
| Relation to SQL | SQL is derived as a combination of relational algebra and relational calculus | SQL is derived as a combination of relational algebra and relational calculus |
| GATE importance | More important for GATE | Less important than relational algebra for GATE |
Revision summary
- Relational algebra and relational calculus are two theoretical languages used on the relational model, studied before SQL.
- A relation/table is treated as a set, and the operations are set operations.
- Relational algebra = what + how.
- Relational calculus = what only, not how.
- SQL is a combination of relational algebra and relational calculus.
- For GATE, relational algebra carries more importance than relational calculus.
Previous-year exam insights
- Relational algebra and safe relational calculus have equal expressive power; unrestricted relational calculus is strictly more expressive because it can express unsafe queries (e.g. infinite or non-domain-dependent results).
Asked inGATE 2002 - Relational calculus comes in two forms: tuple relational calculus (variables range over tuples) and domain relational calculus (variables range over domain values); both are equivalent to relational algebra when restricted to safe expressions.
- Relational algebra is a procedural/operational notation: a query is an expression built from basic operators (select, project, union, set difference, Cartesian product, rename) and derived operators (join, intersection, division, outer joins, aggregation).
- The basic relational algebra operators are select (σ), project (π), union (∪), set difference (−), Cartesian product (×) and rename (ρ); intersection, natural join and division are derived from these.
- Relational calculus is a non-procedural (declarative) notation based on first-order predicate logic: a query is written as {t | P(t)} (tuple calculus) or {x1,...,xn | P(x1,...,xn)} (domain calculus), with no specification of evaluation order.
- A relational calculus expression is safe if its result depends only on the values in the database domain (no infinite relations); only safe calculus expressions correspond to relational algebra queries.
Asked inGATE 2002