0% found this document useful (0 votes)
48 views7 pages

Relational Algebra Operations From Set Theory

Relational Algebra is a query language for databases that utilizes set theory operations such as union, intersection, difference, and Cartesian product to manipulate relations. It also includes binary operations like JOIN, which combines tuples based on common attributes, and DIVISION, which identifies tuples associated with all tuples in another relation. These operations are essential for retrieving and managing data in relational databases.

Uploaded by

zezoadnan10
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)
48 views7 pages

Relational Algebra Operations From Set Theory

Relational Algebra is a query language for databases that utilizes set theory operations such as union, intersection, difference, and Cartesian product to manipulate relations. It also includes binary operations like JOIN, which combines tuples based on common attributes, and DIVISION, which identifies tuples associated with all tuples in another relation. These operations are essential for retrieving and managing data in relational databases.

Uploaded by

zezoadnan10
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/ 7

Relational Algebra Operations from Set Theory

Introduction
Relational Algebra is a fundamental query language used in
databases. It provides a set of operations to manipulate and
retrieve data stored in relational databases. Some of these
operations are derived from set theory, allowing us to
perform operations like union, intersection, difference, and
Cartesian product on relations (tables).
Set-Theoretic Operations in Relational Algebra
1. Union ( ∪ )
Definition:
 The union of two relations R and S (denoted as R ∪ S)
includes all tuples that appear in either R or S or both.
 It removes duplicate tuples since relations are sets (not
multisets).
Conditions:
 Both relations must have the same number of
attributes.
 The corresponding attributes must have the same
domain (same data types).
Example:
Let R(A, B) and S(A, B) be two relations:

A B
1 2
4
3
A B
3 4
5 6

Union Result (R ∪ S):

A B
1 2
3 4
5 6

2. Intersection ( ∩ )
Definition:
 The intersection of two relations R and S (denoted as
R ∩ S) returns only those tuples that are present in both
relations.
Conditions:
 Same as Union (same number of attributes and
domains).
Example:
Intersection Result (R ∩ S):

A B
3 4
3. Set Difference ( − )
Definition:
 The difference of two relations R and S (denoted as R -
S) returns tuples that are in R but not in S.
Example:
Difference Result (R - S):

A B
1 2

Difference Result (S - R):

A B
5 6

4. Cartesian Product ( × )
Definition:
 The Cartesian Product of two relations R and S
(denoted as R × S) combines every tuple of R with
every tuple of S.
 The resulting relation contains all possible pairwise
combinations of tuples.
 Unlike union, intersection, and difference, the
relations do not need to have the same schema.
Example:
Let R(A, B) and S(C, D) be two relations:

A B
1 2
3 4
C D
5 6

Cartesian Product Result (R × S):

A B C D
1 2 5 6
3 4 5 6

Size of Result: If R has m tuples and S has n tuples, then R


× S has m × n tuples.
Binary Relational Operations: JOIN and DIVISION
Binary relational operations are operations that involve
two relations (tables). Among them, JOIN and DIVISION
are fundamental operations in relational algebra.

1. JOIN Operation
The JOIN operation is used to combine tuples from two
relations based on a common attribute. It is one of the
most frequently used operations in databases.
Example of Natural Join
Given relations:

Employee (EID, Name, DeptID)


EID Name DeptID
1 Alice 101
2 Bob 102
3 Carol 103
Department (DeptID, DeptName)
DeptID DeptName
101 HR
102 Finance
Result of Employee ⋈ Department
EID Name DeptID DeptName
1 Alice 101 HR
2 Bob 102 Finance
(Note: Carol is missing because there is no matching
DeptID = 103 in the Department table.)

2. DIVISION Operation
The DIVISION operation is used in queries involving
"all" conditions, such as "Find students who have
completed all required courses." It is useful for finding
tuples in one relation that are associated with all tuples in
another relation.
Definition
If relation R(A, B) is divided by relation S(B), the result
is a relation T(A) containing values of A that are
associated with all values of B in S.
Example
Given relations:

Student_Course (Student, Course)


Student Course
Alice Math
Alice Science
Bob Math
Bob Science
Bob English
Carol Math
Required_Course (Course)
Course
Math
Science

Result of Student_Course ÷ Required_Course

Student
Alice
Bob
(Explanation: Alice and Bob have taken both Math and
Science, while Carol is missing Science, so she is not
included.)

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