These slides cover basic introduction to Relational Algebra which is a part of Relational Database Management System(RDBMS). The content includes basic RA symbols, operations with visualization.
2. RELATIONAL ALGEBRA
Definition: An algebra whose operands are relations or variables that represent
relations.
In database terminology, Relational algebra is a procedural query language.
3. RELATIONAL ALGEBRA
It consists of:
• SELECTION
• PROJECTION
• DIVISION
• UNION
• INTERSECTION
• PRODUCTS
• NATURAL JOIN
• THETA JOIN
• SET DIFFERENCE
• RENAME
• COMPOSITION etc.
5. SELECTION
Selects tuples from a relation whose attributes meet the selection criteria, which is
normally expressed as a predicate.
Notation − σp(r)
Where σ stands for selection predicate and r stands for relation. p is prepositional
logic formula which may use connectors like and, or, and not. These terms may use
relational operators like − =, ≠, ≥, < , >, ≤.
7. PROJECTION
It projects column(s) that satisfy a given predicate.
Notation − πCOl1, COl2, …, COLN(r)
Where COL1, COL2 , COLN are attribute names of relation r.
Duplicate rows are automatically eliminated, as relation is a set.
10. DIVISION
The division is a binary operation that is written as R ÷ S.
Notation − R ÷ S
The result consists of the restrictions of tuples in R to the attribute names unique
to R, i.e., in the header of R but not in the header of S, for which it holds that all their
combinations with tuples in S are present in R.
17. PRODUCT
Combines information of two different relations into one.
Notation − r Χ s
Where r and s are relations and their output will be defined as −
r Χ s = { q t | q ∈ r and t ∈ s}
19. NATURAL JOIN
Combines information of two different relations into one.
Notation − ⋈
Natural join (⋈) is a binary operator that is written as (R ⋈ S) where R and S are
relations. The result of the natural join is the set of all combinations of tuples in R and
S that are equal on their common attribute names.
21. THETA JOIN
Theta join combines tuples from different relations provided they satisfy the theta
condition. The join condition is denoted by the symbol θ.
Notation − R1 ⋈θ R2
R1 and R2 are relations having attributes (A1, A2, .., An) and (B1, B2,.. ,Bn) such that
the attributes don’t have anything in common, that is R1 ∩ R2 = Φ.
23. SET DIFFERENCE
The result of set difference operation is tuples, which are present in one relation but
are not in the second relation.
Notation − A − B
Finds all the tuples that are present in A but not in B.
25. RENAME
Theta join combines tuples from different relations provided they satisfy the theta
condition. The join condition is denoted by the symbol θ.
Notation − ρ x (A)
Where the result of expression A is saved with name of x.
26. COMPOSITION
Composition is the type of relational operation where multiple operations are
performed at once.
Example− A=C(m x n)
27. COMPOSITION(CONTINUED…)
A B C D E
1
1
1
1
2
2
2
2
10
10
20
10
10
10
20
10
a
a
b
b
a
a
b
b
A B C D E
1
2
2
10
10
20
a
a
b
A B
1
2
m
C D E
10
10
20
10
a
a
b
b
n A=C(m x n) A=C(m x n) [Simplified]