Query Languages - Chapter 6

1. Relational Algebra
Express queries by applying specialized operators to relations.
2. Relational Calculus
Queries describe a desired set of tuples by specifying
a predicate the tuples must satisfy.
Relational algebra is an abstract language, by which we mean that it is
not possible to execute queries formulated in relational algebra on an
actual computer. We use relational algebra in order to express in the simplest
form, the set of operations that any relational database query
language must perform. These basic operations ar every helpful in understanding
SQL queries.
Basic Operations
- Union (R U S)
Set of tuples that are in R or S or both.
* R and S must have the same structure
- Difference (R - S)
* Set of tuples in R but not in S.
- Intersection
- Cartesian Product (R * S)
- Project
- Select
- Join
- Division (Quotient)
Example,
A B C D E F
----------- ----------
a b c b g a
d a f d a f
c b d ----------
-----------
R S
Relational Algebra Vs. Relational Calculus
- Relational calculus represents an alternative
to relational algebra.
- Both are equivalent to one another, i.e.,
for each expression of the relational algebra there is an equivalent
in the calculus, likewise.
- The Calculus is closer to natural language, where the
algebra is more like a programming language.
- The calculus simply states what the problem is, the
algebra gives a procedure for solving that problem.
- Relational calculus-based languages are higher-level
than the algebraic ones because the algebra specifies the order of
operations while the calculus leaves it to a compiler to determine
the most efficient order of evaluation.
Last update October 27, 1997.