Databases Reference
In-Depth Information
RELATIONAL ASSIGNMENT
The
Tutorial D
syntax for relational assignment as such—i.e., as opposed to one of the
shorthands such as INSERT or DELETE—takes the following generic form:
R
:=
rx
Here
R
is a relvar reference (i.e., a relvar name, syntactically speaking), and
rx
is a relational
expression, denoting a relation
r
, say, of the same type as relvar
R
. Now, it's easy to see (thanks
to David McGoveran for this observation) that any such assignment is logically equivalent to one
of the following form—
R
:= (
r
MINUS
d
) UNION
i
—where:
r
is the “old” value of
R
d
is a set of tuples to be deleted from
R
(the “delete set”)
i
is a set of tuples to be inserted into
R
(the “insert set”)
5
d
r
(i.e.,
d
is a subset of
r
, meaning we aren't trying to delete any tuples that don't exist)
⊆
i
and
r
are disjoint (meaning we aren't trying to insert any tuples that do already exist)
d
and
i
are disjoint a fortiori
d
and
i
are well defined and unique
6
These points can conveniently be illustrated by means of a Venn diagram (see Fig. 2.2
overleaf).
Explanation:
In that diagram,
r
,
d
, and
i
are as above, and
u
is the universal relation
of the pertinent type (in other words,
u
is the relation whose body consists of all tuples with the
same heading as
R
,
including, of course, those tuples that currently appear in
R
). Note that the
difference
u
-
r
is the absolute complement of
r
(in other words,
u
-
r
is the relation whose body
consists of all tuples with the same heading as
R
that don't currently appear in
R
).
5
Technically, of course,
d
and
i
aren't just “sets of tuples” but in fact relations, of the same type as
r
.
6
See Appendix A for a proof of this claim.