3 - Chapter 2 - Relational Database Modeling - P2
3 - Chapter 2 - Relational Database Modeling - P2
Session 3
Chapter 2 - Relational
Database Modeling - Part 2
Objectives
Sells1 Sells2
bar beer price bar beer price
Joe's Bud 2.50 Joe's Bud 2.50
Joe's Miller 2.75 Joe's Miller 2.75
Sue's Bud 2.50 Sue's Miller 3.00
Sells1 U Sells2
bar beer price
Joe's Bud 2.50
Joe's Miller 2.75
Sue's Bud 2.50
Sue's Miller 3.00
2.4.4. Set Operations on Relations - Set Except
Sells1 Sells2
bar beer price bar beer price
Joe's Bud 2.50 Joe's Bud 2.50
Joe's Miller 2.75 Joe's Miller 2.75
Sue's Bud 2.50 Sue's Miller 3.00
Sells1 \ Sells2
bar beer price
Sue's Bud 2.50
2.4.4. Set Operations on Relations - Set Intersection
This
Sells1 Sells2
bar beer price bar beer price
Joe's Bud 2.50 Joe's Bud 2.50
Joe's Miller 2.75 Joe's Miller 2.75
Sue's Bud 2.50 Sue's Miller 3.00
Sells1 ∩ Sells2
bar beer price
Joe's Bud 2.50
Joe's Miller 2.75
2.4.5. Projection
R1 := πL (R2)
L is a list of attributes from the schema of R2.
R1 is constructed by looking at each tuple of
R2, extracting the attributes on list L, in the
order specified, and creating from those
components a tuple for R1.
Eliminate duplicate tuples, if any.
Example: Projection
Relation Sells:
bar beer price
Joe’s Bud 2.50
Joe’s Miller 2.75
Sue’s Bud 2.50
Sue’s Miller 3.00
R= (A B)
1 2
3 4
πA+B->C, A, A (R) = C A1 A2
3 1 1
7 3 3
2.4.6. Selection
R1 := σC (R2)
C is a condition (as in “if” statements) that
refers to attributes of R2.
R1 is all those tuples of R2 that satisfy C.
Example: Selection
Relation Sells:
bar beer price
Joe’s Bud 2.50
Joe’s Miller 2.75
Sue’s Bud 2.50
Sue’s Miller 3.00
JoeMenu := σbar=“Joe’s”(Sells):
bar beer price
Joe’s Bud 2.50
Joe’s Miller 2.75
2.4.7. Product
R3 := R1 Χ R2
Pair each tuple t1 of R1 with each tuple t2
of R2.
Concatenation t1t2 is a tuple of R3.
Schema of R3 is the attributes of R1 and
then R2, in order.
But beware attribute A of the same name in
R1 and R2: use R1.A and R2.A.
Example: R3 := R1 Χ R2
R ⋈ θ S
R S
A B C D
1 1 2 2
1 2 3 2
2 3 4 1
R⋈B>=CS
A B C D
1 2 2 2
2 3 2 2
2 3 3 2
2.4.11. Renaming
R( bar, addr )
Joe’s Maple St.
Sue’s River Rd.
2.4.11 Combining Operations to Form Queries