Chris R. Timmons said:
Just off the top of my head, taken by itself a NULL value *could*
mean:
- unknown
- not applicable
- always optional
- conditionally optional
- positive infinity
- negative infinity
- error
- required, but can be supplied later
Personally I would never use NULL to represent most of these particular
items. "always optional"? "conditionally optional"? What does that mean?
Has the user filled in all the other columns and failed to populate these
columns? Are they never going to come back and populate these columns? Why
are we using NULLs to indicate this? How about a code indicating "NO
RESPONSE" to an optional question? Or as you mention later, a separate
column with a flag indicating NO RESPONSE? "No Response" is not "unknown".
Neither is "not applicable", or "error".
"positive infinity", "negative infinity"? If you're using NULL like this,
what should the following statement produce:
SELECT SUM(x) FROM table1
Table1
-------
100
200
300
NULL
To be fair, scalar mathematics involving NULL do produce NULL. So 3 + NULL
= NULL. So in this case, is the result Negative Infinity or Positive
Infinity? There's a slight difference... Perhaps if you split attributes
(argh) you could tell the difference. If your result is -Infinity or
+Infinity, it is not "unknown".
"not applicable"? Again, this is something that should be coded and not
left to potential misinterpretation. Let's look at a quick sample of using
NULL to cover these various areas:
Table2
-------
(Last Name, DOB, SSN)
Johnson, 1968-01-01, 000-00-0001
Smith, 1975-10-18, 000-00-1280
Williams, 1961-07-10, NULL
In this instance, Williams has a NULL value in SSN. Which situation
describes why we have a NULL in Williams' SSN column?
1) he has an SSN but we don't know it yet
2) he has no SSN and we know that for a fact
3) Williams refused to supply his SSN
4) it is conditionally optional based on our business rules which say that
we don't need an SSN since we have last name and DOB
5) it is just flat-out optional, period
6) there was an "error" (i.e., we deemed the SSN we received from him as
invalid based on rules set up by the SSA)
Unfortunately, since we used NULL to represent all these different
possibilities we have no idea why we don't have his SSN.
NULL has an inherent meaning, and it is supposed to represent one thing and
one thing only: "unknown/missing" values. Trying to project 7 or 8
different meanings on NULL is not a good practice to get into, and does
little but confuse the design and implementation.