Page 93 - DCAP402_DCAO204_DATABASE MANAGEMENT SYSTEM_MANAGING DATABASE
P. 93
Database Management Systems/Managing Database
Notes When this query is evaluated on an instance of the Sailors relation, the tuple variable S is
instantiated successively with each tuple, and the test S.rating>7 is applied. The answer contains
those instances of S that pass this test. On instance S3 of Sailors, the answer contains Sailors
tuples with sid 31, 32, 58, 71, and 74.
6.2.1 Syntax of TRC Queries
We now define these concepts formally, beginning with the notion of a formula. Let Rel be a
relation name, R and S be tuple variables, a an attribute of R, and b an attribute of S. Let op
denote an operator in the set {<, >, =, , , }. An atomic formula is one of the following:
1. R Rel
2. R. a op S.b
3. R.a op constant, or constant op R.a
A formula is recursively defined to be one of the following, where p and q are themselves
formula, and p (R) denotes a formula in which the variable R appears:
1. Any atomic formula
2. -p, p q, p q, or p q
3. R(p(R), where R is a tuple variable
4. R(p(R), where R is a tupe variable
In the last two clauses above, the quantifiers and are said to bind the variable R. A variable
is said to be free in a formula or subformula (a formula contained in a larger formula) if the (sub)
formula does not contain an occurrence of a quantifier that binds it.
We observe that every variable in a TRC formula appears in a subformula that is atomic, and
every relation schema specifies a domain for each field, this observation ensures that each
variable in a TRC formula has a well-defined domain from which values for the variable are
drawn. That is, each variable has a well-defined type, in the programming language sense.
Informally, an atomic formula R 2 Rel gives R the type of tuples in Rel, and comparisons such as
R.a op S.b and R.a op constant induce type restrictions on the field R.a. If a variable R does not
appear in an atomic formula of the form R 2 Rel (i.e., it appears only in atomic formulas that are
comparisons), we will follow the convention that the type of R is a tuple whose fields include all
(and only) fields of R that appear in the formula.
We will not define types of variables formally, but the type of a variable should be clear in most
cases, and the important point to note is that comparisons of values having different types
should always fail. (In discussions of relational calculus, the simplifying assumption is often
made that there is a single domain of constants and that this is the domain associated with each
field of each relation.)
A TRC query is defined to be expression of of the form {T | p(T)}, where T is the only free
variable in the formula p.
Task Write tuple relational calculus syntax.
86 LOVELY PROFESSIONAL UNIVERSITY