Tag: Relational Algebra

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.

Projection Operator | 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 Projection Operator.

 

Projection Operator-

 

  • Projection Operator (π) is a unary operator in relational algebra that performs a projection operation.
  • It displays the columns of a relation or table based on the specified attributes.

 

Syntax-

 

π<attribute list>(R)

 

Example-

 

Consider the following Student relation-

 

IDNameSubjectAge
100AshishMaths19
200RahulScience20
300NainaPhysics20
400SameerChemistry21

Student

 

Then, we have-

 

Result for Query πName, Age(Student)-

 

NameAge
Ashish19
Rahul20
Naina20
Sameer21

 

Result for Query πID , Name(Student)-

 

IDName
100Ashish
200Rahul
300Naina
400Sameer

 

Important Points-

 

Point-01:

 

  • The degree of output relation (number of columns present) is equal to the number of attributes mentioned in the attribute list.

 

Point-02:

 

  • Projection operator automatically removes all the duplicates while projecting the output relation.
  • So, cardinality of the original relation and output relation may or may not be same.
  • If there are no duplicates in the original relation, then the cardinality will remain same otherwise it will surely reduce.

 

Point-03:

 

  • If attribute list is a super key on relation R, then we will always get the same number of tuples in the output relation.
  • This is because then there will be no duplicates to filter.

 

Point-04:

 

  • Projection operator does not obey commutative property i.e.

π <list2> (π <list1> (R)) ≠ π <list1> (π <list2> (R))

 

Point-05:

 

  • Following expressions are equivalent because both finally projects columns of list-1

π <list1> (π <list2> (R)) = π <list1> (R)

 

Point-06:

 

  • Selection Operator performs horizontal partitioning of the relation.
  • Projection operator performs vertical partitioning of the relation.

 

Point-07:

 

  • There is only one difference between projection operator of relational algebra and SELECT operation of SQL.
  • Projection operator does not allow duplicates while SELECT operation allows duplicates.
  • To avoid duplicates in SQL, we use “distinct” keyword and write SELECT distinct.
  • Thus, projection operator of relational algebra is equivalent to SELECT operation of SQL.

 

Next Article- Set Theory Operators in Relational Algebra

 

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

Watch video lectures by visiting our YouTube channel LearnVidFun.

Relational Algebra | Relational Algebra in DBMS

Relational Algebra-

 

Relational Algebra is a procedural query language which takes a relation as an input and generates a relation as an output.

 

Relational Algebra Operators-

 

The operators in relational algebra may be classified as-

 

 

We will discuss all these operators one by one in detail.

 

Characteristics-

 

Following are the important characteristics of relational operators-

 

  • Relational Operators always work on one or more relational tables.
  • Relational Operators always produce another relational table.
  • The table produced by a relational operator has all the properties of a relational model.

 

Next Article- Selection Operator in Relational Algebra

 

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

Watch video lectures by visiting our YouTube channel LearnVidFun.