Binary Operators in Relational Algebra
All those Operators that operate on two operands are known as Binary operators.
Types of Binary Operators
There are 3 types of binary operators, which are given below
- Union Operators
- Cross Product
- Difference operator
1. Union Operator (∪)
Let A and B be two relations.
Then
- A ∪ B is the set of all tuples belonging to either A or B or both.
- In A ∪ B, duplicates are automatically removed.
- Union operation is both commutative and associative.
Example:
Consider the following two relations: A and B,
Relation A
And Relation B
Then, A ∪ B is
2. Cartesian/CROSS Product
The cross-product is a way of combining two tables. The resulting table will contain each of the attributes in both tables being combined.
- It is denoted by ‘✕’ symbol
If A and B are two tables and need a cross-product between them, then it will be given below
- A ✕ B, Where A and B are the two tables,
Example:
Consider following tables
“Student” Table
And “Student_Detail” Table
Applying CROSS PRODUCT on STUDENT and Student_Detail tables is given below.
Important Terms
- The cardinality (Number of Tuples/Rows):
Number of Tuples after Cross product = Rows of A table + Rows of B table - Degree (No of Columns)
Number of columns after Cross product = columns of A table X columns of B table
In the above table, We can see that the number of tuples (Rows) in the STUDENT relation is 2, and the number of tuples in the Student_DETAIL table is 2.
- So, the number of tuples in the resulting table after performing CROSS PRODUCT is 2 x 2 = 4.
- The number of columns will be the sum of the total columns in both tables, so 3+2=5
3. Difference Operator (-)
Let A and B be two relations.
Then
- A – B is the set of all tuples belonging to A and not to B.
- In A – B, duplicates are automatically removed.
- Difference operation is associative but not commutative.
Example
Consider the following two relations: A and B
Relation A
Relation B
Then, A – B is