It seems to me to avoid columns with a null value. Where domain semantics allow the use of a value that explicitly indicates missing data, it should be used instead of NULL.
For example, imagine a table containing a Comment field. Most developers posted NULL here to indicate that there is no data in the column. (And, hopefully, a control restriction that prohibits zero-length strings so that we have a known "value" indicating no value.) My approach is usually the opposite. The Comment column is NOT NULL , and a row of length zero indicates no value. (I use a check constraint to ensure that a zero-length string is indeed a zero-length string, not a space.)
So why should I do this? Two reasons:
NULL requires special logic in SQL, and this method avoids this.- Many client libraries have special values that indicate
NULL . For example, if you use Microsoft ADO.NET, the constant DBNull.Value indicates NULL, and you should check it. Using a row of zero length in a NOT NULL column eliminates the need.
Despite all this, there are many circumstances in which NULL are accurate. In fact, I do not mind using them in the above scenario, although this will not be my preferred method.
Whatever you do, be kind to those who will use your tables. Be consistent . Allow them with confidence SELECT . Let me explain what I mean. I recently worked on a project whose database was not developed by me. Almost every column was nullable and had no limits. There was no agreement on what constitutes a lack of value. It could be NULL , a string with zero length, or even a bunch of spaces, and often was. (How this soup of values got there, I don't know.)
Imagine the ugly code that a developer must write to find all of these entries with a missing Comment field in this scenario:
SELECT * FROM Foo WHERE LEN(ISNULL(Comment, '')) = 0
Surprisingly, there are developers who consider this to be quite acceptable, even normal, despite the potential performance implications. Better would be:
SELECT * FROM Foo WHERE Comment IS NULL
or
SELECT * FROM Foo WHERE Comment = ''
If your table is designed correctly, you can use the above two SQL statements to get high-quality data.