|From:||darcy(at)druid(dot)net (D'Arcy J(dot)M(dot) Cain)|
|To:||archie(at)netg(dot)se (Archibald Zimonyi)|
|Subject:||Re: NULL values or not?|
|Views:||Raw Message | Whole Thread | Download mbox|
Thus spake Archibald Zimonyi
> I have a question about NULL values. Lets say that we have a world with
> the following info:
> Everyone has to have a FirstName and LastName but not everyone has to have
> a PhoneNumber.
> Personally I don't like NULL values, so I would have created to tables for
> the above world roughly like this:
Why don't you like NULLs? NULLs are an important part os SQL. however...
> CREATE TABLE person
> id int2,
> firstname text,
> lastname text
> CREATE TABLE phonenumbers
> id int2,
> phonenumber text
> with keys and indexes and such things.
> A SELECT statement to retireve all info from these two tables would look
> like this:
> SELECT firstname, lastname, phonenumber
> FROM person
> LEFT JOIN phonenumbers USING (id);
How about this?
CREATE TABLE person
firstname text DEFAULT '',
lastname text NOT NULL,
phonenumber text DEFAULT ''
Now you can simply list everything and the phone number will be blank if
you don't have one. Note that I do the same for firstname since I am not
as convinced as you are that everyone needs two names. With your philosopy
you would need to break out another table. Worse, some people only have
first names and some only have last names.
I also put a NOT NULL constraint on lastname to force an entry there
although you can still insert a blank.
However, don't reject NULLs out of hand. They can be very important
especially when you have foreign keys and such. It's much cleaner to
put a NULL in a field when you don't know than to have to add a special
"Unknown" entry in the foreign table.
|Next Message||Aasmund Midttun Godal||2001-12-21 12:41:24||Re: NULL values or not?|
|Previous Message||Jan Wieck||2001-12-21 12:29:56||Re: NULL values or not?|