• Welcome, Guest. Please login.
 
September 17, 2019, 02:36:02 pm

News:

Welcome to the SQLitening support forums!


Null instead of space/0.

Started by Fim, April 03, 2017, 06:40:38 am

Previous topic - Next topic

Fim

Is it better to set a field to null than space or zero?
/Fim W.
Fim W

Bern Ertl

Depends upon what you want.  I have fields in my database tables that I use NULL as indicating 'no data' versus a zero value (state of the data can be important).  Other fields I use DEFAULT 0 in the table creation call to ensure it's never NULL.

Fim

Fim W

cj

April 03, 2017, 07:00:38 pm #3 Last Edit: April 03, 2017, 07:24:28 pm by cj
I agree with never using them
https://www.bennadel.com/blog/85-why-null-values-should-not-be-used-in-a-database-unless-required.htm

Is there a NULL dollar amount?  Is the amount unknown?   I would use 0.
Another thing is "Was the NULL wanted or did it get into the database by skipping an entry?
Ever try printing a NULL?

The NULL when copied to other file types can cause a problem with files that do not support 0 length.
Some other database languages do not index NULL which is an exception and I would consider them in that case.

If there is a column where null is needed it sounds like a good candidate for another table so the entry is not made.

Example:  A table that allows unlimited phone numbers linked to client table
type   client  phone
Work  1        5551212
Home 1        5551212
Cell    1        NULL         (not needed)

NULL can complicate a SQL search

1 vote for never use them.





Paul Squires

I never use NULL either. I find that it complicates things unnecessarily.