Databases Reference
In-Depth Information
However, I did also note that the foregoing explanation required some slight refinement in
the case where two or more of the individual assignments specify the same target variable. Now
I'd like to explain that refinement, briefly.
First of all, consider the following simple example:
DELETE ( S WHERE SNO = 'S1' ) FROM S ,
DELETE ( S WHERE SNO = 'S2' ) FROM S ;
Here's the corresponding expanded form:
S := S MINUS ( S WHERE SNO = 'S1' ) ,
S := S MINUS ( S WHERE SNO = 'S2' ) ;
Clearly, then, if both source expressions are evaluated before either of the individual assignments
is executed, then one of these two assignments has no effect!—in other words, one of the
DELETEs is “lost.” (And to make matters worse, which of the two is lost is apparently not even
defined.)
Because of situations like the foregoing, the definition of multiple assignment is extended
to say, in effect, that if two or more of the individual assignments in that multiple assignment
specify the same target variable, then those particular individual assignments are executed in
sequence as written. A little more precisely, we can say of the foregoing double assignment that
it's logically equivalent to the following single assignment:
S := WITH ( S := S MINUS ( S WHERE SNO = 'S1' ) ) :
S MINUS ( S WHERE SNO = 'S2' ) ;
This assignment in turn is equivalent to the following:
WITH ( DELETE ( S WHERE SNO = 'S1' ) FROM S ) :
DELETE ( S WHERE SNO = 'S2' ) FROM S ;
Note: Of course, the particular double assignment we're considering here is logically
equivalent to the following single assignment:
S := ( S MINUS ( S WHERE SNO = 'S1' ) ) MINUS ( S WHERE SNO = 'S2' ) ;
More generally, it's intuitively obvious that a multiple assignment in which all of the
individual assignments specify the same target relvar R is logically equivalent to some single
assignment to that same relvar R . Why? Because any assignment, multiple or otherwise, to
relvar R effectively assigns some “new” value R - d
i to R , for some d and some i .
Of course, the foregoing observation, while obviously correct, is of no help in computing
the actual values of d and i in the general case. But the following remarks might help a little in
this regard. Consider the following double assignment (and note carefully that the relvar
 
Search WWH ::




Custom Search