Escolar Documentos
Profissional Documentos
Cultura Documentos
Lecture 2
K
Korra
Sathya
S th B
Babu
b
Department of Computer Science
NIT R
Rourkela
k l
1/22/2011
Lecture 2
Relational Calculus
RA and RC are formal Languages of Relational model
RA is Procedural and RC is Declarative (non procedural)
Example
Sno
Sname
Rating
Age
Sid
bid
day
bid
bname
color
22
Dustine
45.0
22
101
10/10/08
101
Interlake
Blue
29
Brutus
33.0
22
102
10/10/08
102
Interlake
Red
31
Lubber
55.5
22
103
10/08/08
103
Clipper
Green
32
Andyy
25.5
22
104
10/07/08
104
Marine
red
58
Rusty
10
35.0
31
102
10/10/08
64
Horatio
35.0
31
103
11/06/08
71
Zorba
10
16 0
16.0
31
104
11/12/08
74
Horatio
35.0
64
101
09/05/08
85
Art
25.5
64
102
09/08/08
95
B b
Bob
63 5
63.5
74
103
09/08/08
Instance of Sailors
1/22/2011
Instance of Boats
Instance of Reserves
Lecture 2
1/22/2011
Lecture 2
Algebra
g
Vs Calculus
condition (formula)(R) = { T/ R (T) formula }
1,2,..,k (R) = { tk/ (u) (R(u) t[1] = u[i1] .. t[k] = u[ik] }
R S = { t/ R(t) S(t) }
R S = { t/ R(t) S(t) }
R X S = {tr+s/ (ur) (vs) (R(u) S(v) t[1] = u[i1] .. t[r] = u[r]
t[r+1] = v[1] .. t[r+s] = v[s] }
1/22/2011
Lecture 2
TRC Examples
Find all sailors with a rating above 7.
1/22/2011
Lecture 2
1/22/2011
Lecture 2
Means There
There exists a Branch Tuple with same
branchNo as the branchNo of the current Staff tuple,
T, and is located in Rourkela.
1/22/2011
Lecture 2
1/22/2011
Lecture 2
1/22/2011
Lecture 2
10
{ P | S Sailors
S l
B Boats
B
(R Re serves( S .sid = R.sid R.bid = B.bid P.sname = S .sname))
1/22/2011
Lecture 2
11
Tuple
p Relational Calculus
Expressions can generate an infinite set.It is possible
to write syntactically correct calculus queries that
have an infinite number of answers! Such queries
are called unsafe.
For example
{ S/~Staff(S) }
S | S Sailors
To avoid this,
this add restriction that all values in result
must be values in the domain of the expression.
1/22/2011
Lecture 2
12
1/22/2011
Lecture 2
13
1/22/2011
Lecture 2
14
I, N , T , A | I, N , T , A Sailors T > 7
1/22/2011
Lecture 2
15
1/22/2011
Lecture 2
16
B, BN, C Boats
1/22/2011
Lecture 2
17
Summary
Relational calculus is non-operational,
queries in terms of
and users define q
what they want, not in terms of how to
p
it. (Declarativeness.)
(
)
compute
Algebra and safe calculus have same
expressive power
power, leading to the notion
of relational completeness.
1/22/2011
Lecture 2
18