Relational Algebra is defined as the set of methods which are applied to retrieve the data based on the defined requirements.
Those set of methods are called as Operators of Relational Algebra.
These Operators are divided into two types:
- Native Operators
- Set Theoretic Operators
Before knowing in detail about these operators we need to understand the following four definitions.
Degree d(R): Total no of attributes/columns present in a relation/table is called degree of the relation and is denoted by d(R).
Cardinality |R|: Total no if tuples present in a relation or Rows present in a table, is called cardinality of a relation and is denoted by |R|.
Domain: Total range of accepted values for an attribute of the relation is called the domain of the attribute.
Union Compatibility: Two relations R and S are set to be Union Compatible to each other if and only if:
- They have the same degree d(R).
- Domains of the respective attributes should also be same.
Now coming back to Operators:
- Set Theoretic
- Union (∪)
- Intersection (∩)
- Minus (–)
- Cartesian Product (X)
- Native
- Selection (σ)
- Projection (π)
- Rename (ρ)
- Divide (÷)
- Join
Note: In order to apply Union, Intersection and Minus operators among any two given relations, the prerequisite is those relations should always be Union Compatible with each other.
suppose there are two relations R and S then following properties hold true:
d(R∪S) = d(R) = d(S) and max(|R|,|S|) ≤ |R∪S| ≤ |R| + |S|
d(R∩S) = d(R) = d(S) and 0 ≤ |R∩S| ≤ min(|R|,|S|)
d(R-S) = d(R) = d(S) and 0 ≤ |R-S| ≤ (|R|) or 0 ≤ |S-R| ≤ (|S|)
Example:
R | S | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
R∪S
A/C | B/D |
---|---|
1 | x |
2 | y |
3 | z |
4 | p |
5 | q |
6 | s |
7 | t |
R∩S
A/C | B/D |
---|---|
1 | x |
R-S
A/C | B/D |
---|---|
2 | y |
3 | z |
One comment