Set Theory Operations in Relational Algebra

14 May, 2020
Prerequisite – Relational Algebra in DBMSThese Set Theory operations are the standard mathematical operations on set. These operations are Binary operation that is, these are operated on 2 relations unlike PROJECT, SELECT and RENAME operations. These operations are used to merge 2 sets in various ways.
The set operation are mainly categorized into the following:
Union operationIntersection operationSet difference or Minus operation
Union operation
Intersection operation
Set difference or Minus operation
Before we apply one of the 3 set operations on relations, the two relations on which we are performing the operations must have same type of tuples. This is also known as be Union compatibility (or Type compatibility).
Type compatibility: Two relations A(P1, P2, ..., Pn) and B(Q1, Q2, ..., Qn) are said to be Type compatible (or Union compatible) if both the relation have same degree ‘k’ and
domain(Pi) = domain(Qi) for 1<= i <= k. 
1. UNION Operation:
Notation: 
A ∪ S

where, A and S are the relations,
symbol ‘∪’  is used to denote the Union operator.
The result of Union operation, which is denoted by A ∪ S, is a relation that basically includes all the tuples that are present in A or in S, or in both, eliminating the duplicate tuples.
Important points on UNION Operation:
1. The UNION operation is commutative, that is :
A ∪ B = B ∪ A
2. The UNION is associative, that means it is applicable to any number of relation.
A ∪ ( B ∪ C ) = ( A ∪ B ) ∪ C
3. In SQL, the operation UNION is as same as UNION operation here.
4. Moreover, In SQL there is multiset operation UNION ALL.
2. INTERSECTION Operation:
Notations:
A ∩ S

where, A and S are the relations,
symbol ‘∩’  is used to denote the Intersection operator.
The result of Intersection operation, which is denoted by A ∩ S, is a relation that basically includes all the tuples that are present in both A an S.
Important points on INTERSECTION Operation:
1. The INTERSECTION operation is commutative, that is :
A ∩ B = B ∩ A
2. The INTERSECTION is associative, that means it is applicable to any number of relation.
A ∩ ( B ∩ C ) = ( A ∩ B ) ∩ C
3. INTERSECTION can be formed using UNION and MINUS as follows:
A ∩ B = ((A ∪ B) - (A - B)) - (B - A)
4. In SQL, the operation INTERSECT is as same as INTERSECTION operation here.
5. Moreover, In SQL there is multiset operation INTERSECT ALL.
3. MINUS (or SET DIFFERENCE) Operation:
Notations:
A - S

where, A and S are the relations,
symbol ‘ – ’  is used to denote the Minus operator.
The result of Intersection operation, which is denoted by A – S, is a relation that basically includes all the tuples that are present in A but not in S.
Important points on MINUS (or SET DIFFERENCE) Operation:
1. The SET DIFFERENCE operation is not commutative, that means :
A - B != B - A
2. In SQL, the operation EXCEPT is as same as MINUS operation here.
3. Moreover, In SQL there is multiset operation EXCEPT ALL.
Example:Consider a relation Student(FIRST, LAST) and Faculty(FIRSTN, LASTN) given below :
1. Student UNION Faculty :
Student ∪ Faculty 
2. Student INTERSECTION Faculty :
Student ∩ Faculty 
3. Student MINUS Faculty :
Student - Faculty
DBMS-Relational Algebra
DBMS
GATE CS
DBMS
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
CTE in SQL
Difference between Clustered and Non-clustered index
Introduction of DBMS (Database Management System) | Set 1
Introduction of B-Tree
SQL Interview Questions
Layers of OSI Model
TCP/IP Model
Types of Operating Systems
Page Replacement Algorithms in Operating Systems
Inter Process Communication (IPC)