374
Relations, Functions, and Matrices
Ordinary comparisons (does 2 = 2? does 2 = 5?) result in True or False
values, but when a NULL value is involved, the result, as we have seen, will be
NULL. This introduces a three-valued logic where expressions can have values
of True, False, or NULL. Truth tables can be written for three-valued logic (see
Exercise 53 of Section 1.1).
a
B
a ` B
T
T
T
T
F
F
T
N
N
F
T
F
F
F
F
F
N
F
N
T
N
N
F
F
N
N
N
a
B
a ~ B
T
T
T
T
F
T
T
N
T
F
T
T
F
F
F
F
N
N
N
T
T
N
F
N
N
N
N
a
a′
T
F
F
T
N
N
Most database management systems follow these rules of three-valued logic
until a final truth value decision must be made, and then a NULL value gets set to
False. But this can have unexpected consequences. For example, if Bruno is added
to the Pet table and the following SQL query is executed
seLeCtPetName
FrOM Pet
Where PetType = “Dog”
aND NOt (Breed = “Collie”);
we may expect to see Bruno’s name in the resulting relation, since Bruno’s breed
is not “Collie.” But as Bruno’s attribute values are compared with the criteria
specified in the SQL statement, we get
PetType = “Dog”AND NOT (Breed = “Collie”)
“Dog” = “Dog”AND NOT (NULL = “Collie”)
True AND NOT NULL
True AND NULL
NULL
which then is set to False, so Bruno does not satisfy this query. On second thought,
because Bruno’s breed is NULL, he might actually be a collie; this query result
reflects the fact that it cannot be said with certainty that Bruno is a noncollie dog.
But consider the SQL query
seLeCt PetName
FrOM Pet
Where PetType = “Dog”
aND Breed = NULL;
Précédent

- 391/986

Suivant