Lecture7 Rel-Alg
Lecture7 Rel-Alg
π
CS 33102
Lecture 7
By relieving the brain of all unnecessary
work, a good notation sets it free to
concentrate on more advanced problems,
and, in effect, increases the mental power of
the race.
-- Alfred North Whitehead (1861 - 1947)
These slides are taken from the slides from
(CS186 EECS Berkley by Prof. Michael
Franklin) and are modified incorporating other
sources.
The set of allowed values for each attribute is called the domain
of the attribut
Attribute values are (normally) required to be atomic; that is,
indivisibl
The special value null is a member of every domai
The null value causes complications in the definition of many
operations
e
Database
A database consists of multiple relation
Information about an enterprise is broken up into part
instructor
student
adviso
Bad design:
univ (instructor -ID, name, dept_name, salary, student_Id, ..)
results i
Keys
Let K ⊆
K is a superkey of R if values for K are sufficient to identify a unique tuple
of each possible relation r(R)
Example: {ID} and {ID,name} are both superkeys of instructor
R1 S1 =
!
S1! R1 =
!! S1.sid< R1.sid
Boats
bid bname color
101 Interlake Blue
102 Interlake Red
103 Clipper Green
104 Marine Red
Find names of sailors who’ve reserved boat #103
ρ (Tempboats, (σ Boats))
color =' red ' ∨ color =' green '
π sname(Tempboats !
!Re serves !
!Sailors)
Find sailors who’ve reserved a red and a green boat
• Previous approach won’t work! Must identify
sailors who’ve reserved red boats, sailors who’ve
reserved green boats, then find the intersection
(note that sid is a key for Sailors):
π sname((Tempred ∩ Tempgreen) !
!Sailors)
Find the names of sailors who’ve reserved all boats