s
Section 5.3 Relations and Databases
373
in order to process a query, we give a set-theoretic description of the desired result
of the query. We specify what we want, not how to get it. Sounds like Prolog (see
Section 1.5). In fact, the description of the set may involve notation from predicate
logic; remember that predicate logic is also called predicate calculus, hence the
name relational calculus. Relational algebra and relational calculus are equivalent
in their expressive power; that is, any query that can be formulated in one language can be formulated in the other.
example 26
The relational calculus expression for the query asking for the names of all cats
whose owners live in Illinois is
Range of x is PetOwner
Range of y is Person
5x.PetName 0 x.PetType = “Cat” and
exists y(y.Name = x.Name and y.State = “IL”)6
(4)
Here “Range of x is PetOwner” specifies the relation from which the tuple x may
be chosen, and “Range of y is Person” specifies the relation from which the tuple
y may be chosen. (The use of the term range is unfortunate. We are really talking
about domain in the same sense we talked about the domain of an interpretation in
predicate logic—the pool of potential values.) The notation “exists y” stands for
the existential quantifier ( E y).
Expressions (1) through (4) all represent the same query expressed in English
language, relational algebra, SQL, and relational calculus, respectively.
PRaCtiCe 22 Using the relations Person and PetOwner, express the following query in relational algebra,
SQL, and relational calculus form:
Give the names of all cities where dog owners live.
■
null values and three-valued logic
The value of an attribute in a particular tuple may be unknown, in which case the
attribute is assigned a NULL value. For example, we might have the tuple
Bruno, Dog, NULL
in the Pet table if Bruno is a dog of unknown breed. (Note that Bruno’s breed
might be unknown in some absolute sense, or it might simply be unknown to the
person entering the data.)
Because NULL means “unknown value,” any comparisons between a NULL
value and any other value must result in NULL. Thus
“Poodle” = NULL
results in NULL; since the NULL value is unknown, it is also unknown whether
it has the value “Poodle.”
RemInDeR
Any comparison involving
a NULL value results in
NULL.
Précédent

- 390/986

Suivant