Databases Reference
In-Depth Information
Multivariable Constraints
There's another matter I need to discuss briefly in connection with constraints as opposed to
predicates (though the matter in question really has to do with constraints in general, not just
view constraints in particular). First of all, recall this simple example from Chapter 2:
CONSTRAINT CX1 IS_EMPTY ( S WHERE STATUS < 1 ) ;
This example is expressed in Tutorial D , of course, but for reasons that will quickly
become clear I want to show the same constraint (or at least the boolean expression portion of
the constraint, which is to say the portion between the constraint name CX1 and the terminating
semicolon) in relational calculus instead: 11
NOT EXISTS x S ( x .STATUS < 1 )
Or equivalently:
FORALL x S ( x .STATUS ≥ 1 )
In these formulations, the subexpression “ x ∈ S” (which can be read as “ x such that x is a tuple in
the current value of S”) defines the variable x to be a range variable , “ranging over” the current
value of relvar S. In other words, the permitted values of x at any given time are exactly the
tuples appearing in the relation that's the value of relvar S at the time in question.
As a basis for further examples, consider view LS once again (“London suppliers”),
together with its companion view NLS (“non London suppliers”). Here are relational calculus
formulations of a couple of obvious constraints that apply to these two views:
FORALL x LS ( x .CITY = 'London' )
FORALL x NLS ( x .CITY 'London' )
Now, all of the constraints we've seen in this section so far have been single-variable
constraints, because each of them involves just one range variable. Here by contrast is an
example of a multivariable constraint (it's basically constraint CX3 from Chapter 2):
FORALL x S ( FORALL y SP
( IF x .STATUS < 20 AND x .SNO = y .SNO THEN y .PNO 'P6' ) )
11 Refer to SQL and Relational Theory if you need further explanation of relational calculus expressions like those discussed in
this section.
Search WWH ::




Custom Search