Why are quantifiers needed in Tuple Relational Calculus?
Lets say I have this statement:
{S.sname | S in Student and (exists G in Grade )(S.s# = G.s#)};
Why can't I just use this instead?
{S.sname | S in Student and G in Grade and S.s# = G.s#};
Why are quantifiers needed in Tuple Relational Calculus?
Lets say I have this statement:
{S.sname | S in Student and (exists G in Grade )(S.s# = G.s#)};
Why can't I just use this instead?
{S.sname | S in Student and G in Grade and S.s# = G.s#};
The queries return the same value. But in the second example you could also ask for the G.grade
of the student whereas in the first you can't. The right hand side of a Tuple Relational Calculus expression describes a set of tuples of which only the attributes from the left hand side are kept. Here the two right hand side expressions describe different sets of tuples, but the projection on the left hand side happens to leave the same value from both.
The difference between
r IN R AND EXISTS s IN S (
etc
)
r IN R AND s IN S AND
etc
is that the relation described by first only has the attributes of R
whereas the relation described by the second has the attributes of R
& S
.
Suppose any relation T
with attributes ...
holds the rows where some expression T(...)
holds. Then <...> IN T
if and only if T(...)
.
Then we can describe the two relations above as the tuples satisfying (respectively)
R(...) AND EXISTS
attributes in S & etc but not in R
(S(...) AND
etc
)
R(...) AND S(...) AND
etc
This notation (more or less) is called Domain Relational Calculus.
Suppose we define the following operators on relations:
PROJECT
some attributes of T
T
holds the rows where EXISTS
other attributes of T
T(...)
T NATURAL JOIN U
holds the rows where T(...) AND U(...)
Then we can describe the two relations above as the tuples in (respectively)
R NATURAL JOIN PROJECT
attributes in S & etc also in R
(S NATURAL JOIN
etc
)
R NATURAL JOIN S NATURAL JOIN
etc
This notation is called Relational Algebra.