Professional Documents
Culture Documents
Relational Algebra
Relational Algebra
Module 3, Lecture 1
Preliminaries
Example Instances
R1 sid
22
58
31
44
58
bid
day
101 10/10/96
103 11/12/96
Relational Algebra
Basic operations:
Additional operations:
Intersection, join, division, renaming: Not essential, but
(very!) useful.
Projection
sname
rating
yuppy
lubber
guppy
rusty
9
8
5
10
sname,rating(S2)
age
35.0
55.5
age(S2)
7
Selection
rating >8(S2)
sname rating
yuppy 9
rusty
10
sid sname
22 dustin
rating age
7
45.0
S1 S2
Database Management Systems, R. Ramakrishnan
22
31
58
44
28
dustin
lubber
rusty
guppy
yuppy
7
8
10
5
9
45.0
55.5
35.0
35.0
35.0
S1 S2
sid sname rating age
31 lubber 8
55.5
58 rusty
10
35.0
S1 S2
9
Cross-Product
22
dustin
45.0
22
101 10/10/96
22
dustin
45.0
58
103 11/12/96
31
lubber
55.5
22
101 10/10/96
31
lubber
55.5
58
103 11/12/96
58
rusty
10
35.0
22
101 10/10/96
58
rusty
10
35.0
58
103 11/12/96
Renaming operator:
10
Joins
Condition Join:
R >< c S = c (R S)
S1 ><
(sid) bid
58
103
58
103
day
11/12/96
11/12/96
R1
11
Joins
S1 ><
R1
sid
Result schema similar to cross-product, but only
one copy of fields for which equality is specified.
Natural Join: Equijoin on all common fields.
12
Division
13
pno
p1
p2
p3
p4
p1
p2
p2
p2
p4
pno
p2
B1
pno
p2
p4
B2
pno
p1
p2
p4
B3
sno
s1
s2
s3
s4
sno
s1
s4
sno
s1
A/B1
A/B2
A/B3
14
A/B:
x ( A)
x (( x ( A) B) A)
all disqualified tuples
15
Solution 1:
Solution 2:
sname((
bid =103
(Temp1,
bid = 103
Re serves)
Solution 3:
sname (
bid =103
sname ((
Boats) >< Re serves >< Sailors)
color =' red '
sname ( ((
17
Boats))
18
(Tempred,
sid
(Tempgreen,
((
sid
((
19
(Tempsids, (
sid, bid
Re serves) / (
bid
Boats))
bid
Boats)
20