Database Systems - Lecture 7
Database Systems - Lecture 7
RELATIONAL ALGEBRA
Relational Algebra is a procedural query language which defines a set of operations that take one or
two relations as input and produce a new relation as output.
In Relational Algebra, each operation specifies a sequence of steps to perform or retrieve the desired
result.
These are applicable because each relation is defined to be a set of tuples in the formal relational model
and they include:
• UNION
• INTERSECTION
• SET DIFFERENCE/ MINUS/EXCEPT, and
• CARTESIAN PRODUCT (CROSS PRODUCT).
1
UNION OPERATOR (∪)
Then-
• R ∪ S is the set of all tuples belonging to either R or S or both.
• In R ∪ S, duplicates are automatically removed.
• Union operation is both commutative and associative.
EXAMPLE-
Then, R ∪ S is
Relation RUS
2
INTERSECTION OPERATOR (∩)-
Let R and S be two relations.
Then-
• R ∩ S is the set of all tuples belonging to both R and S.
• In R ∩ S, duplicates are automatically removed.
• Intersection operation is both commutative and associative.
EXAMPLE
Then, R ∩ S is
3
Difference operation is associative but not commutative.
EXAMPLE
Consider the following two relations R and S
Then, R – S is
4
EXAMPLE
Consider: Table R1 –
Find R1 X R2
5
RELATIONAL ALGEBRA OPERATIONS DEVELOPED SPECIFICALLY FOR
RELATIONAL DATABASES
These include:
• SELECT
• PROJECT and
• JOIN, among others.
• SELECT (symbol: σ)
• PROJECT (symbol: π)
• RENAME (symbol: ρ)
SELECT (σ)
EXAMPLE 1
7
𝜋(𝐴, 𝐵) gives
EXERCISE