Set Theory Operators | Relational Algebra | DBMS

Relational Algebra Operators-

 

Before you go through this article, make sure that you have gone through the previous article on Introduction to Relational Algebra.

 

The operators in relational algebra are classified as-

 

 

In this article, we will discuss about Set Theory Operators.

 

Set Theory Operators-

 

Following operators are called as set theory operators-

 

 

  1. Union Operator (∪)
  2. Intersection Operator (∩)
  3. Difference Operator (-)

 

Condition For Using Set Theory Operators

 

To use set theory operators on two relations,

The two relations must be union compatible.

Union compatible property means-

  • Both the relations must have same number of attributes.
  • The attribute domains (types of values accepted by attributes) of both the relations must be compatible.

 

Also read- Selection Operator and Projection Operator

 

1. Union Operator (∪)-

 

Let R and S be two relations.

Then-

  • R ∪ S is the set of all tuples belonging to either R or S or both.
  • In R ∪ S, duplicates are automatically removed.
  • Union operation is both commutative and associative.

 

Example-

 

Consider the following two relations R and S-

 

IDNameSubject
100AnkitEnglish
200PoojaMaths
300KomalScience

Relation R

 

IDNameSubject
100AnkitEnglish
400KajolFrench

Relation S

 

Then, R ∪ S is-

 

IDNameSubject
100AnkitEnglish
200PoojaMaths
300KomalScience
400KajolFrench

Relation R ∪ S

 

2. Intersection Operator (∩)-

 

Let R and S be two relations.

Then-

  • R ∩ S is the set of all tuples belonging to both R and S.
  • In R ∩ S, duplicates are automatically removed.
  • Intersection operation is both commutative and associative.

 

Example-

 

Consider the following two relations R and S-

 

IDNameSubject
100AnkitEnglish
200PoojaMaths
300KomalScience

Relation R

 

IDNameSubject
100AnkitEnglish
400KajolFrench

Relation S

 

Then, R ∩ S is-

 

IDNameSubject
100AnkitEnglish

Relation R ∩ S

 

3. Difference Operator (-)-

 

Let R and S be two relations.

Then-

  • R – S is the set of all tuples belonging to R and not to S.
  • In R – S, duplicates are automatically removed.
  • Difference operation is associative but not commutative.

 

Example-

 

Consider the following two relations R and S-

 

IDNameSubject
100AnkitEnglish
200PoojaMaths
300KomalScience

Relation R

 

IDNameSubject
100AnkitEnglish
400KajolFrench

Relation S

 

Then, R – S is-

 

IDNameSubject
200PoojaMaths
300KomalScience

Relation R – S

 

Get more notes and other study material of Database Management System (DBMS).

Watch video lectures by visiting our YouTube channel LearnVidFun.

Summary
Set Theory Operators | Relational Algebra | DBMS
Article Name
Set Theory Operators | Relational Algebra | DBMS
Description
In Relational Algebra, Set theory operators are- Union operator, Intersection operator, Difference operator. Condition for using set theory operators- Both the relations must be union compatible.
Author
Publisher Name
Gate Vidyalay
Publisher Logo
Liked this article? Share it with your friends and classmates now-