tags:

views:

53

answers:

3

The data in my dabatase comes from an external source and where ever there is no data passed, I keep NULL in those places. Can anyone tell me if there are any implications in using NULL to represent empty value? Should I follow some other convention like 'data_not_available'? or something like that?

Can anyone suggest?

+1  A: 

I've always used NULL. I've seen arguments saying NULL was a hack and should never have been put into mainstream use and it's now out of control, but I can't think of a better way to treat something as having "no value."

After all how you can represent a number as having no value? 0 is a value. -1 is a value. -9999999 is a value.

Also foreign keys depend on a NULL value to signify there is no related record.

Andy Shellam
exactly. Even I cannot think to name something better than NULL
JPro
+1  A: 

Wikipedia's entry on NULL in SQL is actually very informative. NULL is acceptable, but can often indicate database design problems, where data should reside in a separate table with a FK.

Aiden Bell
what do you suggest then?
JPro
for example, say there is a field with 'Description_of_Item' and say the customer does not want fill in , for this type is it OK to keep 'NULL'?
JPro
matter of taste/performance. I might use NULL while others put descriptions in another table.
Aiden Bell
+1  A: 

Conceptually, NULL means "a missing unknown value" and it is treated somewhat differently from other values. For example, to test for NULL in MySQL, you cannot use the arithmetic comparison operators such as =, <, or <>.

Since you will be having columns that may have "missing or unkown" values, you have to set them to accept NULL. On the other hand, a table with many NULL columns may be indicating that this table needs to be refactored into smaller tables that better describe the entities they represent.

Note that in general using a convention like 'data_not_available' is not recommended. Using NULLs is the convention, and your DBMS already knows about it.

Daniel Vassallo
thanks for the suggestion
JPro