Why are quantifiers needed in Tuple Relational Calculus?

828 Views Asked by At

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#};

1

There are 1 best solutions below

0
On

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 ANDetc
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 EXISTSattributes in S & etc but not in R(S(...) ANDetc)
R(...) AND S(...) ANDetc
This notation (more or less) is called Domain Relational Calculus.

Suppose we define the following operators on relations:
PROJECTsome attributes of TT holds the rows where EXISTSother attributes of TT(...)
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 PROJECTattributes in S & etc also in R(S NATURAL JOINetc)
R NATURAL JOIN S NATURAL JOINetc
This notation is called Relational Algebra.