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

Database Systems - Lecture 7

Uploaded by

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

Database Systems - Lecture 7

Uploaded by

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

RELATIONAL ALGEBRA AND RELATIONAL CALCULUS

RELATIONAL ALGEBRA
Relational Algebra is a procedural query language which defines a set of operations that take one or
two relations as input and produce a new relation as output.
In Relational Algebra, each operation specifies a sequence of steps to perform or retrieve the desired
result.

RELATIONAL ALGEBRA OPERATIONS FROM THE MATHEMATICAL SET THEORY

These are applicable because each relation is defined to be a set of tuples in the formal relational model
and they include:

• UNION
• INTERSECTION
• SET DIFFERENCE/ MINUS/EXCEPT, and
• CARTESIAN PRODUCT (CROSS PRODUCT).

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

Then, R ∪ S is

Relation RUS

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

Then, R ∩ S is

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.

3
 Difference operation is associative but not commutative.

EXAMPLE
Consider the following two relations R and S

Then, R – S is

CARTESIAN PRODUCT OPERATION (X)


• It combines two relations, R1 and R2 without any condition.
• It is denoted by X. E.g. R1 X R2.
• Degree of R1 X R2 = degree of R1 + degree of R2
Where {degree = total no of columns}

4
EXAMPLE
Consider: Table R1 –

Find R1 X R2

5
RELATIONAL ALGEBRA OPERATIONS DEVELOPED SPECIFICALLY FOR
RELATIONAL DATABASES
These include:
• SELECT
• PROJECT and
• JOIN, among others.

UNARY RELATIONAL OPERATIONS

• SELECT (symbol: σ)
• PROJECT (symbol: π)
• RENAME (symbol: ρ)

BINARY RELATIONAL OPERATIONS


• JOIN
• DIVISION

SELECT (σ)

• It is used to project required column data from a relation.


• The projection eliminates all attributes of the input relation but displays those mentioned in
the projection list.
• The projection method defines a relation that contains a vertical subset of Relation.
• This helps to extract the values of specified attributes to eliminate duplicate values.

EXAMPLE 1

Consider the following table:


6
EXAMPLE 2
Consider the following relation. Suppose we want columns B and C from Relation R.

7
𝜋(𝐴, 𝐵) gives

EXERCISE

You might also like