Open In App

Set Theory Operations in Relational Algebra

Last Updated : 05 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Relational Algebra in DBMS These Set Theory operations are the standard mathematical operations on set. These operations are Binary operations that 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 is mainly categorized into the following:

  1. Union operation
  2. Intersection operation
  3. 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 the 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 :

FirstLast
AishaArora
BikashDutta
MakkuSingh
RajuChopra
FirstNLastN
RajKumar
HoneyChand
MakkuSingh
KaranRao

1. Student UNION Faculty :

Student ∪ Faculty 
FirstLast
AishaArora
BikashDutta
MakkuSingh
RajuChopra
RajKumar
HoneyChand
KaranRao

2. Student INTERSECTION Faculty :

Student ∩ Faculty 
FirstLast
MakkuSingh

3. Student MINUS Faculty :

Student - Faculty
FirstLast
AishaArora
BikashDutta
RajuChopra

Next Article

Similar Reads