0% found this document useful (0 votes)
114 views15 pages

Relational Algebra - 6

The document discusses relational algebra, which is a procedural query language for retrieving data from relational databases. It defines six basic relational algebra operators: selection, projection, Cartesian product, union, difference, and join. Each operator is explained along with examples of how it can be used in a query. Relational algebra provides a way to express queries as the composition of these operators applied to tables.

Uploaded by

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

Relational Algebra - 6

The document discusses relational algebra, which is a procedural query language for retrieving data from relational databases. It defines six basic relational algebra operators: selection, projection, Cartesian product, union, difference, and join. Each operator is explained along with examples of how it can be used in a query. Relational algebra provides a way to express queries as the composition of these operators applied to tables.

Uploaded by

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

Relational Algebra

Reference Book :
Principles of Distributed Database Systems
EDITION THIRD
Author: M. Tamer Ozsu

Course:DDB
Instructor: Ibrar Afzal

Hazara University Mansehra, IT Department

1
Relational Algebra
Procedural vs .non-procedural, or declarative
“Pure” languages:
Relational algebra
Tuple relational calculus
Domain relational calculus
The above 3 pure languages are equivalent in computing
power
relational algebra is procedural in that the user is predictable
and use high-level operators
Not turning-machine equivalent
consists of 6 basic operations

2
Relational Algebra Operators

Symbol (Name) Example of Use


σ
σ
(Selection) salary > = 85000 (instructor)
Return rows of the input relation that satisfy the predicate.
Π
Π
(Projection) ID, salary (instructor)
Output specified attributes from all rows of the input relation. Remove
duplicate tuples from the output.
x
(Cartesian Product) instructor x department
Output pairs of rows from the two input relations that have the same value on
all attributes that have the same name.

Π ∪ Π
(Union) name (instructor) name (student)
Output the union of tuples from the two input relations.
-
Π -- Π
(Set Difference) name (instructor) name (student)
Output the set difference of tuples from the two input relations.

(Natural Join) instructor ⋈ department
Output pairs of rows from the two input relations that have the same value on
all attributes that have the same name.

3
Select Operation – selection of rows (tuples)
The SELECT operation (denoted by  (sigma)) acts as a filter and
select a subset of the tuples from a relation

 Relation r

A=B ^ D > 5 (r)

4
Project Operation – selection of columns (Attributes)
PROJECT Operation is denoted by  (pi) and creates a vertical
partitioning for columns (attributes).
Relation r:

 A,C (r)

5
Union of two relations
operation, denoted by  and attributes must be type compatible (have same or compatible

Relations r, s:

 r  s:

6
Set difference of two relations
Called MINUS or EXCEPT and result of r – s, is a relation that includes all
tuples that are in r but not in s

Relations r, s:

 r – s:

7
Set intersection of two relations
Result of the intersection operation r  s, is a relation that
includes all tuples that are in both r and s
Relation r, s:

r  s

Note: r  s = r – (r – s)

8
Joining two relations -- Cartesian-product
Operation is used to combine tuples from two relations and resulting relation
state has one tuple for each combination of tuples—one from r and one from s.

 Relations r, s:

 r x s:

9
Cartesian-product – naming issue
 Relations r, s: B

 r x s: r.B s.B

10
Composition of Operations
Can build expressions using multiple operations
Example: A=C (r x s)

r x s

A=C (r x s)

11
Joining two relations – Natural Join

12
Natural Join Example

13
Notes about Relational Languages
Each Query input is a table (or set of tables)
Each query output is a table.
All data in the output table appears in one of the
input tables
Relational Algebra is not Turning complete
Can we compute:
SUM
AVG
MAX
MIN

14
Thanks

15

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