Databases Reference
In-Depth Information
Consider a relvar R with just two attributes, K and A. Let {K} be the sole key; further, let
K and A both be of type INTEGER, and let R contain just two tuples, (1,2) and (3,-2). 9 Now
consider the following explicit UPDATE operations:
UPDATE R : { K := K + A } ;
UPDATE R : { A := - A } ;
Note in particular that the first of these is a “key UPDATE” and the second isn't; thus, if a
compensatory action of the form ON UPDATE K … had been defined (which it well might have
been, in an SQL context), that action would presumably be invoked in connection with the first
UPDATE and not the second. And yet it's easy to see that, given the specified initial value for
R, the two UPDATEs are effectively equivalent—in fact, they're both equivalent to this explicit
assignment: 10
R := RELATION { TUPLE { K 1 , A - 2 } , TUPLE { K 3 , A 2 } } ;
In other words, the delete set d is the same for both of the original UPDATEs, and so is the
insert set i . ( Exercise: What are they, exactly?) Clearly, therefore, what we want is for
compensatory actions, if any, to be driven by the applicable delete set and insert set as such, not
by the arbitrary choice of syntax in which the pertinent update happens to have been formulated.
INTEGRITY CONSTRAINTS
Every relvar is subject to a set of integrity constraints, or just constraints for short. First of all, as
we know from the section “Relations and Relvars,” any given relvar is constrained to be of a
certain type (more specifically, a certain relation type)—namely, the type specified when the
relvar in question is defined. For example, here again is the definition of the suppliers relvar S: 11
VAR S BASE RELATION
{ SNO CHAR , SNAME CHAR , STATUS INTEGER , CITY CHAR }
KEY { SNO } ;
As you can see, this definition states explicitly that relvar S is of type RELATION {SNO CHAR,
SNAME CHAR, STATUS INTEGER, CITY CHAR}. What's more, it's immediate from that
specification that attributes SNO, SNAME, STATUS, and CITY are of types CHAR, CHAR,
9 Here and elsewhere in this topic I adopt this simplified notation for tuples in the interest of readability.
10 The expression on the right side of this assignment is a relation selector invocation —in fact, a relation literal . Refer to SQL
and Relational Theory if you need further explanation of such matters.
11 Relvar S is a base relvar, of course. For views, see Chapter 3.
Search WWH ::




Custom Search