17
Relational Algebra Jermaine Rodney

Relational Algebra

Embed Size (px)

DESCRIPTION

Relational Algebra. Jermaine Rodney. What is an “Algebra”. Mathematical system consisting of: Operands --- Variables or values from which new values can be constructed. Operators --- Symbols denoting procedures that construct new values from given values. What is Relational Algebra?. - PowerPoint PPT Presentation

Citation preview

Page 1: Relational Algebra

Relational Algebra

Jermaine Rodney

Page 2: Relational Algebra

What is an “Algebra”

Mathematical system consisting of:Operands --- Variables or values from which

new values can be constructed.

Operators --- Symbols denoting procedures that construct new values from given values.

Page 3: Relational Algebra

What is Relational Algebra? An Operators are mathematical

functions used to retrieve queries by describing a sequence operations on tables or even databases(schema) involved.

Page 4: Relational Algebra

Relational algebra received little attention outside of pure mathematics until the publication of E.F. Codd's relational model of data in 1970. Codd proposed algebra as a basis for database query languages.

Page 5: Relational Algebra

Core Relational Algebra

The relational algebra uses set union, set difference, and Cartesian product from set theory, but adds additional constraints to these operators.

Page 6: Relational Algebra

Constraints

For set union and set difference, the two relations involved must be union-compatible—that is, the two relations must have the same set of attributes. Because set intersection can be defined in terms of set difference, the two relations involved in set intersection must also be union-compatible.

Page 7: Relational Algebra

Constraints cont.

For the Cartesian product to be defined, the two relations involved must have disjoint headers—that is, they must not have a common attribute name.

Page 8: Relational Algebra

Core Relational Algebra

Selection: picking certain rows. Projection: picking certain columns. Joins: compositions of relations. Renaming of relations and attributes etc.

Page 9: Relational Algebra

Operations

Projection (π) Selection (σ) Rename (ρ) Natural join ( )⋈ Division (÷) Cartesian product (×) Set intersection (∩) Set union ( )∪

Page 10: Relational Algebra

Selection Operation

PROFID# NAME DEPT RANK SAL.

1 Adam CS ASST 6000

2 Bob EE ASSO 8000

3 Calvin CS FULL 10000

4 Dorothy EE ASST 5000

5 Emily EE ASSO 8500

6 Frank CS FULL 9000

σSAL. >= 8500(PROF) ∩ σDEPT = CS(PROF)

Selection (σ)

Page 11: Relational Algebra

σSAL. >= 8500(PROF) ∩ σdept = CS(PROF)

returns:

ID# NAME DEPT RANK SAL.3 Calvin CS FULL 10000

6 Frank CS FULL 9000

Page 12: Relational Algebra

Natural Join

Denoted by T1 T⋈ 2 Where T1 andT2 are tables. The output of the operation is a table T

such that:The schema of T includes all the distinct

columns of T1 andT2 .

Page 13: Relational Algebra

TEACH

ID# CID YEAR

1 C1 2011

2 C2 2012

1 C2 2012

Page 14: Relational Algebra

PROF TEACH ⋈Returns:

ID# NAME DEPT RANK SAL. CID YEAR

1 Adam CS ASST 6000 C1 2011

2 Bob EE ASSO 8000 C2 2012

1 Adam CS ASST 6000 C2 2012

Natural join ( )⋈

Page 15: Relational Algebra

Renaming The ρ operator gives a new schema to a

relation. R1 := ρ R1(A1,...,An) (R2) makes R1 be

a relation with attributes A1,...,An and the same tuples as R2.

Simplified notation: R1(A1,...,An):= R2.

Page 16: Relational Algebra

Example: Renaming

Bars( )

R(bar, addr):=Bars

R ( )bar addrJoe’s Maple St.

Sue’s River RD.