0% found this document useful (0 votes)
2 views

Relational Algebra

Relational Algebra defines operators that transform input relations into output relations, allowing for complex queries on database data. Key operations include Selection (σ), Projection (∏), Union (∪), Set Difference (-), Cartesian Product (X), and Rename (ρ), each serving specific purposes in data retrieval and manipulation. Examples illustrate how these operators can be applied to relations such as STUDENT and EMPLOYEE to obtain desired results.

Uploaded by

budhiabarik66
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Relational Algebra

Relational Algebra defines operators that transform input relations into output relations, allowing for complex queries on database data. Key operations include Selection (σ), Projection (∏), Union (∪), Set Difference (-), Cartesian Product (X), and Rename (ρ), each serving specific purposes in data retrieval and manipulation. Examples illustrate how these operators can be applied to relations such as STUDENT and EMPLOYEE to obtain desired results.

Uploaded by

budhiabarik66
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Relational Algebra

The main purpose of using Relational Algebra is to define operators that transform
one or more input relations into an output relation. Given that these operators
accept relations as input and produce relations as output, they can be combined
and used to express potentially complex queries that transform potentially many
input relations (whose data are stored in the database) into a single output relation
(the query results).

STUDENT

ROLL NAME AGE


1 Aman 20
2 Atul 18
3 Baljeet 19
4 Harsh 20
5 Prateek 21
6 Prateek 23

EMPLOYEE

EMPLOYEE_NO NAME AGE


E-1 Anant 20
E-2 Ashish 23
E-3 Baljeet 25
E-4 Harsh 20
E-5 Pranav 22
1. Selection (σ) :

Select operation is done by Selection Operator which is represented by "sigma"(σ). It is used to


retrieve tuples(rows) from the table where the given condition is satisfied. It is a unary
operator means it requires only one operand.

Notation : σ p(R)

Where σ is used to represent SELECTION


R is used to represent RELATION
p is the logic formula
Let's understand this with an example:
Suppose we want the row(s) from STUDENT Relation where "AGE" is 20.

σ AGE=20 (STUDENT)

This will return the following output:

ROLL NAME AGE


1 Aman 20
4 Harsh 20

2. Projection ( ∏ )

Project operation is done by Projection Operator which is represented by "pi"(∏). It is used to


retrieve certain attributes (columns) from the table. It is also known as vertical partitioning as it
separates the table vertically.

Notation : ∏ a(r)

Where ∏ is used to represent PROJECTION


r is used to represent RELATION
a is the attribute list
Let's understand this with an example:
Suppose we want the names of all students from STUDENT Relation.

∏ NAME(STUDENT)
This will return the following output:

NAME
Aman
Atul
Baljeet
Harsh
Prateek

For multiple attributes

∏ ROLL,NAME(STUDENT)

ROLL NAME
1 Aman
2 Atul
3 Baljeet
4 Harsh
5 Prateek
6 Prateek

3. Union (∪)

Union operation is done by Union Operator which is represented by "union"(∪). It is the

Notation: R ∪ S
same as the union operator from set theory.

Where R is the first relation

∏ NAME(STUDENT) ∪ ∏ NAME(EMPLOYEE)
S is the second relation

NAME
Aman
Anant
Ashish
Atul
Baljeet
Harsh
Pranav
Prateek

4. Set Difference (-)


Set Difference as its name indicates is the difference between two relations (R-S). It is denoted
by a "Hyphen"(-) and it returns all the tuples(rows) which are in relation R but not in relation S.
It is also a binary operator.

Notation : R – S

Where R is the first relation


S is the second relation

∏ NAME(STUDENT) - ∏ NAME(EMPLOYEE)

This will give us the following output:

NAME
Aman
Atul
Prateek

5. Cartesian product (X)

Cartesian product is denoted by the "X" symbol. Let's say we have two relations R and S.
Cartesian product will combine every tuple(row) from R with all the tuples from S.

Notation: R X S

Where R is the first relation


S is the second relation

STUDENT X EMPLOYEE

ROLL NAME AGE EMPLOYEE_NO NAME AGE


1 Aman 20 E-1 Anant 20
1 Aman 20 E-2 Ashish 23
1 Aman 20 E-3 Baljeet 25
1 Aman 20 E-4 Harsh 20
1 Aman 20 E-5 Pranav 22
2 Atul 18 E-1 Anant 20
2 Atul 18 E-2 Ashish 23
2 Atul 18 E-3 Baljeet 25
2 Atul 18 E-4 Harsh 20
ROLL NAME AGE EMPLOYEE_NO NAME AGE
2 Atul 18 E-5 Pranav 22

6. Rename (ρ)

Rename operation is denoted by "Rho"(ρ). As its name suggests it is used to rename the output
relation. Rename operator too is a binary operator.

Notation: ρ(R,S)

Where R is the new relation name


S is the old relation name

ρ(STUDENT_NAME,∏ NAME(STUDENT))

STUDENT_NAME

NAME
Aman
Atul
Baljeet
Harsh
Prateek

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy