Relational algebra is a formal system for handling relations. With it, we can perform various operations on relations, similar to how we can perform union, intersection, or difference on sets. The result of the operations is always another relation, so we stay within the set of relations (closure).
Basic Operations
Union: R ∪ S = { (a,b) | (a,b) ∈ R or (a,b) ∈ S }. Defined only if R and S come from the same universe.
Intersection: R ∩ S = { (a,b) | (a,b) ∈ R and (a,b) ∈ S }.
Difference: R - S = { (a,b) | (a,b) ∈ R and (a,b) ∉ S }.
Complement: R^c = all pairs in the universe not in R.
Composition: R ∘ S = { (a,c) | ∃ b: (a,b) ∈ R and (b,c) ∈ S }.
Example
Let R = { (1,2), (2,3) }, S = { (3,4) }, universe U = {1,2,3,4} × {1,2,3,4}.
R ∪ S = { (1,2), (2,3), (3,4) }.
R ∩ S = ∅.
R - S = { (1,2), (2,3) }.
R ∘ S = { (2,4) } because (2,3) ∈ R and (3,4) ∈ S.
Properties
Operations are closed on the set of relations.
Union and intersection are commutative and associative.
Composition is associative but generally not commutative.
Complement behaves according to De Morgan's laws.
Summary
Relational algebra provides a formal tool for handling relations. Its basic operations allow combining, filtering, and transforming relations, which is of central importance in mathematics and the world of databases.
Practice Exercise
We have reviewed and checked the materials, but errors may still occur. The content is provided for educational purposes only, so use it at your own responsibility and verify with other sources if needed.
✨ Ask Lara
Relational algebra is the formal system for handling relations. Basic operations: union, intersection, difference, complement, composition. Easy-to-understand explanation with examples.
Please sign in to ask Lara about Relational Algebra.