Here is my problem:
Where I work, I need to run reports on a very large database. I’m using basic SQL queries in PHP to filter for exactly what I want. Every so often I’ll get groups in my reports that do not meet the criteria of my search query.
I noticed that all of the “stragglers” that appear in my reports seemed to have NULL values in certain fields, consistently.
Looking at the database structure, I find that these NULL values in the database have a NOT NULL flag set on them.
It turns out that these are actually not NULL values and instead empty string values or $value = ”
In my past experience, when I was starting out I would make this mistake a lot, setting something = ” instead of making it NULL.
I’ve asked the DBA if he can think of any legitimate reason why these are set this way ( there are 300,000 some odd records that are like this ) and he had no clue.
I’m thinking it could be another programmers mistake or someone attempting to avoid not being able to insert the record due to the “NOT NULL” flag set on that specific field.
So I’m scratching my head over here trying to find a legitimate reason for these to exist, other than my own suspicions that the database was not designed for these 2 types of records: records with this value and records without this value.
What are your thoughts?
The use of NULL as a value in database has its critics, I’d like to refer to the Wikipedia article on NULL for an explanation of some of the oddities NULL may introduce in your queries.
So probably the database architect wasn’t a fan of NULLs, maybe after reading “the Third Manifesto”. This PDF (by one of the authors of the Third Manifesto) can help you understand the problem and show you how to manage the special case of missing values can be handled.