2

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

philipxy
  • 14,867
  • 6
  • 39
  • 83
user1766555
  • 57
  • 1
  • 3
  • 11
  • I thnk this is similar to your question, which I was also looking up: http://cs.stackexchange.com/questions/37861/when-should-you-use-the-existential-and-universal-quantifiers-for-relational-cal The problem is that there isn't a concrete answer except maybe because quantifying sort of makes the bound variables private (and free variables are arguments)?? Do provide an answer if you find one. – abhink Oct 23 '16 at 17:37
  • Please give a reference for the variant of TRC you are using. – philipxy Oct 30 '16 at 08:35

1 Answers1

2

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.

philipxy
  • 14,867
  • 6
  • 39
  • 83