Relational Algebra
Relational Algebra
The main purpose of using Relational Algebra is to define operators that transform
one or more input relations into an output relation. Given that these operators
accept relations as input and produce relations as output, they can be combined
and used to express potentially complex queries that transform potentially many
input relations (whose data are stored in the database) into a single output relation
(the query results).
STUDENT
EMPLOYEE
Notation : σ p(R)
σ AGE=20 (STUDENT)
2. Projection ( ∏ )
Notation : ∏ a(r)
∏ NAME(STUDENT)
This will return the following output:
NAME
Aman
Atul
Baljeet
Harsh
Prateek
∏ ROLL,NAME(STUDENT)
ROLL NAME
1 Aman
2 Atul
3 Baljeet
4 Harsh
5 Prateek
6 Prateek
3. Union (∪)
Notation: R ∪ S
same as the union operator from set theory.
∏ NAME(STUDENT) ∪ ∏ NAME(EMPLOYEE)
S is the second relation
NAME
Aman
Anant
Ashish
Atul
Baljeet
Harsh
Pranav
Prateek
Notation : R – S
∏ NAME(STUDENT) - ∏ NAME(EMPLOYEE)
NAME
Aman
Atul
Prateek
Cartesian product is denoted by the "X" symbol. Let's say we have two relations R and S.
Cartesian product will combine every tuple(row) from R with all the tuples from S.
Notation: R X S
STUDENT X EMPLOYEE
6. Rename (ρ)
Rename operation is denoted by "Rho"(ρ). As its name suggests it is used to rename the output
relation. Rename operator too is a binary operator.
Notation: ρ(R,S)
ρ(STUDENT_NAME,∏ NAME(STUDENT))
STUDENT_NAME
NAME
Aman
Atul
Baljeet
Harsh
Prateek