Relational algebra is a procedural query language that defines a set of operations on relations. Each operation takes one or more relations as input and produces a new relation as output. This closure property means operations can be composed arbitrarily. Relational algebra serves as the theoretical foundation for query languages such as Structured Query Language.
The six fundamental operations are sufficient to express any relational algebra query. All other operations can be derived from these.
Selects tuples from a relation that satisfy a given predicate.
where
Example:
Selects specified attributes from a relation, removing duplicates from the result.
Example:
Returns all tuples that appear in either of two union-compatible relations.
Requires
Returns all tuples in the first relation that are not in the second.
Combines every tuple of one relation with every tuple of another.
where
Renames either the relation or its attributes.
renames relation
These operations can be expressed in terms of the fundamental operations but are used so frequently that they have their own notation.
Returns tuples present in both relations.
Combines tuples from two relations that agree on all common attributes, then projects out the duplicate columns. The natural join is central to the theory of lossless-join decomposition.
Returns tuples in
Assigns the result of a relational algebra expression to a temporary relation variable. This is purely notational convenience for breaking complex expressions into steps.
| Property | Operations |
|---|---|
| Commutative | |
| Associative | |
| Not commutative |
Selection is idempotent:
Selections can be cascaded:
Projections can be cascaded: