4 ms·
There are plenty of uses for null. For example: last failed login date. What do you put if it never happened? You put NULL. As a general rule, there is no good
by ars 18y ago
There are plenty of uses for null. For example: last failed login date. What do you put if it never happened? You put NULL.
As a general rule, there is no good "empty" value for things that are not strings, so you use NULL for those.
For your boolean: you have a new user and want to ask if he wants the widget enabled. They could say yes or no - but until you ask, you set it to NULL, and it's an excellent flag for your application that means: ask the user.
If you have never used NULLs in your databases, well, that's more a failing on your part than a failing on the concept of NULL.
Sometimes you want them, and sometimes you don't - that's why the database asks you.
NULL is used as the answer to x/0.
NULL is used to indicate lack of records on an outer join.
If you ask for the average value of something - and there are no rows, you get NULL - what else should it return? 0 is not the correct answer.
> a computer that says "I don't know" is not a useful computer
And a computer that returns incorrect information is worse. You asked it "what are the total sales for august". You did not ask "what are the sales so far for august".
Without the NULL as the answer, how does your front end application know to collect the running average to display to the user? You most certainly do have to detect NULL.
I will admit it's very rare to use NULL instead of an empty string (in fact in some versions of oracle NULL and the empty string are the same). But NULL is used frequently for other datatypes. And it's used frequently in other parts of databases.
- chime 18y agoThanks for the reply. Very good points. NULL is perfect for DIV/0 or no record in join errors. I have absolutely nothing against that. It's the NULL instead of empty string that really bothers me and causes problems. Setting the field to NOT NULL has its own set of problems when used over ODBC. I know it's not the fault of the DB but the problem still remains.