Page 94 - DCAP402_DCAO204_DATABASE MANAGEMENT SYSTEM_MANAGING DATABASE
P. 94

Unit 6: Relational Language and Database Design




          6.2.2  Semantics of TRC Queries                                                       Notes

          What does a TRC query mean? More precisely, what is the set of answer tuples for a given TRC
          query? The answer to a TRC query {T | p(T)}, as we noted earlier, is the set of all tuples t for
          which the formula p(T) evaluates to true with variable T assigned the tuple value t. To complete
          this definition, we must state  which assignments  of tuple values to  the free  variables in a
          formula make the formula evaluate to true.
          A query is evaluated on a given instance of the database. Let each free variable in a formula F be
          bound to a tuple value. For the given assignment of tuples to variables, with respect to the given
          database instance, F evaluates to (or simply ‘is’) true if one of the following holds:
          1.   F is an atomic formula R   Rel, and R is assigned a tuple in the instance of relation Rel.

          2.   F is a comparison R.a op S.b, R.a op constant, or constant op R.a, and the tuples assigned to
               R and S have field values R.a and S.b that make the comparison true.
          3.   F is of the form –p and q is not true, or of the form p  q, and both p and q are true, or of the
               form p  q, and one of them is true, or of the form p  q and q is true whenever p is true.
          4.   F is the form  R(p(R)), and there is some assignment of tuples to the free variables in p(R),
               including the variable R, that makes the formula p(R) true.
          5.   F is the form   R(p(R)), and there is some assignment of tuples to the free variables in p(R)
               that makes the formula p(R) true no matter what tuple is assigned to R.

          6.3 Domain Relational Calculus

          A domain variable is a variable that ranges over the values in the domain of some attribute (e.g.,
          the variable can be assigned an integer if it appears in an attribute whose domain is the set of
          intergers). A DRC query has the form {<x , x , . . . . , x > | p (<x , x , . . . . , x >)}, where each x  is
                                           1  2      n       1  2     n             i
          either a domain variable or a constant and p (<x , x , . . . . , x >)} denotes a DRC formula whose
                                                 1  2     n
          only free variables are the variables among the x , 1 < i < n. The result of this query is the set of
                                                 i
          all tuples <x , x , . . . . , x > for which the formula evaluates to true.
                    1  2      n
          A DRC formula is defined in a manner that is very similar to the definition of a TRC formula.
          The main difference is that the variables are now domain variables. Let op denote an operator in
          the set {<,>,=,   ,   ,   } and let X and Y be domain variables.
          An atomic formula in DRC is one of the following:

          1.   <x , x , . . . . , x >  Rel, where Rel is a relation with n attributes, each x , 1  i  n is either a
                 1  2     n                                            i
               variable or a constant.
          2.   X op Y

          3.   X op constant, or constant op X
          A formula is recursively defined to one of the following, where p and q are themselves formulas,
          and p(X) denotes a formula in which the variable X appears:

          1.   Any atomic formula
          2.   -p, p  q, p  q, or p   q
          3.     X(p(X), where X is a domain variable

          4.     X(p(X), where X is a domain variable





                                           LOVELY PROFESSIONAL UNIVERSITY                                   87
   89   90   91   92   93   94   95   96   97   98   99