Are nulls in a relational database okay? [closed]

There's a school of thought that null values should not be allowed in a relational database. That is, a table's attribute (column) should not allow null values. Coming from a software development background, I really don't understand this. It seems that if null is valid within the context of the attribute, then it should be allowed. This is very common in Java where object references are often null. Not having an extensive database experience, I wonder if I'm missing something here.


Solution 1:

Nulls are negatively viewed from the perspective of database normalization. The idea being that if a value can be nothing, then you really should split that out into another sparse table such that you don't require rows for items which have no value.

It's an effort to make sure all data is valid and valued.

In some cases having a null field is useful, though, especially when you want to avoid yet another join for performance reasons (although this shouldn't be an issue if the database engine is setup properly, except in extraordinary high performance scenarios.)

-Adam

Solution 2:

One argument against nulls is that they don't have a well-defined interpretation. If a field is null, that could be interpreted as any of the following:

  • The value is "Nothing" or "Empty set"
  • There is no value that makes sense for that field.
  • The value is unknown.
  • The value hasn't been entered yet.
  • The value is an empty string (for databases that don't distinguish between nulls and empty strings).
  • Some application-specific meaning (e.g., "If the value is null, then use a default value.")
  • An error has occurred, causing the field to have a null value when it really shouldn't.

Some schema designers demand that all values and data types should have well-defined interpretations, therefore nulls are bad.