Relational Algebra & Calculus
Dr.S.Sivakumar,Principal
C.P.A College, Bodinayakanur
1
Relational Query Languages
2
Formal Relational Query Languages
3
Preliminaries
4
Example Instances
R1
S1
S2
5
Relational Algebra
6
Projection
7
Selection
8
Union, Intersection, Set-Difference
9
Cross-Product (Cartesian Product)
10
Joins: used to combine relations
11
Join
12
Properties of join
13
Division
14
Examples of Division A/B
A
B1
B2
B3
A/B1
A/B2
A/B3
15
Example of Division
16
Example of Division
R1: Find all branches in Chville
R2: Find (bname, cname) pair from Account
R3: Customers in r2 with every branch name in r1
17
Expressing A/B Using Basic Operators
Disqualified x values:
A/B:
all disqualified tuples
18
Exercises
Given relational schema:
Sailors (sid, sname, rating, age)
Reservation (sid, bid, date)
Boats (bid, bname, color)
19
Summary of Relational Algebra
20
Relational Algebra & Calculus
Chapter 4, Part B (Relational Calculus)
21
Relational Calculus
22
Domain Relational Calculus
make the formula be true.
simple atomic formulas (getting tuples from
relations or making comparisons of values),
and building bigger and better formulas using
the logical connectives.
23
DRC Formulas
24
Free and Bound Variables
25
Find all sailors with a rating above 7
26
Find sailors rated > 7 who have reserved boat #103
27
Find sailors rated > 7 who’ve reserved a red boat
28
Find sailors who’ve reserved all boats
29
Find sailors who’ve reserved all boats (again!)
.....
Any other way to specify it? Equivalence in logic
30
Unsafe Queries, Expressive Power
31
Exercise of tuple calculus
Given relational schema:
Sailors (sid, sname, rating, age)
Reservation (sid, bid, date)
Boats (bid, bname, color)
32
Summary of Relational Calculus
33