When using integer columns is it better to have 0
or NULL
to indicate no value.
For example, if a table had a parent_id
field and a particular entry had no parent, would you use 0
or NULL
?
I have in the past always used 0
, because I come from a Java world were (prior to 1.5) integers always had to have a value.
I am asking mainly in relation to performance, I am not too worried about which is the “more correct” option.
Advertisement
Answer
Using NULL
is preferable, for two reasons:
NULL
is used to mean that the field has no value, which is exactly what you’re trying to model.- If you decide to add some referential integrity constraints in the future, you will have to use
NULL
.