Professional Documents
Culture Documents
• Today:
– Theory: Relational Calculus
– Practical: SQL (time permitting)
• Next Week:
– Practical: SQL, Query Processing
Review – Query Languages
• High level query langs important aspect of DBMSs
– Less work for user asking query
– More opportunities for optimization
• English:
Find all sailors with a rating above 7
b • If a is true, b must
T F be true!
– If a is true and b is
false, the implication
T T F evaluates to false.
a • If a is not true, we
don’t care about b
F T T
– The expression is
always true.
Quantifier Shortcuts
Note the use of to find a tuple in Reserves that `joins with’ the Sailors tuple under consideration.
R.bid = 103))}
Exercises
• Find the names of sailors who’ve reserved any red boat
{N | S Sailors
(S.name = N.name
R Reserves
(S.sid = R.sid
B Boats(B.color = “Red”
B.bid = R.bid)))}
Exercises
• Find sailors who’ve reserved a red boat or a green boat
{S | S Sailors
(R Reserves
(S.sid = R.sid
B Boats(B.bid = R.bid
(B.color = “Red”
B.color = “Green” ))))}
Exercises
• Find sailors who’ve reserved a red boat and a green boat
{S | S Sailors
((R Reserves
(S.sid = R.sid
B Boats(B.color = “Red” B.bid = R.bid)))
(R Reserves
(S.sid = R.sid
B Boats(B.color = “Green” B.bid = R.bid))))}
Exercises
• Find sailors who’ve reserved all red boats
{S | SSailors
B Boats(B.color = ‘red’
R(RReserves S.sid = R.sid
B.bid = R.bid))}
{S | SSailors
B Boats (B.color ‘red’
R(RReserves S.sid = R.sid
B.bid = R.bid))}
Unsafe Queries, Expressive Power
• syntactically correct calculus queries that have an infinite
number of answers! Unsafe queries.
– e.g.,
S| S Sailors
– Solution???? Don’t do that!