what's better? NULL or empty text?
what's better, for a cell to contain a value of NULL or empty text like '' ..?
is there an advantange one way or another?
I suspect using NULL might make searches a bit more efficient in some cases, but that's just speculation on my part. The main reason I'd consider using NULL is for the ability to filter on it with IS NULL and IS NOT NULL. It just seems a bit cleaner to me to do...
SELECT * FROM foo WHERE bar IS NOT NULL ORDER BY something
(Even though the 2nd version takes fewer keystrokes, for some reason the first seems clearer and more semantically correct to me.)
SELECT * FROM foo WHERE bar != '' ORDER BY something
Also, depending on what DBMS you are using, some have nifty shortcuts for sorting all nulls to the top or bottom regardless of ASC or DESC sort order, which can sometimes be useful.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Very interesting, I never really gives this a major thought. I simply uses "" (empty string).
Most related functions I used are coded in PHP. So I never uses NULL.
It might come in handy if you do use the functions inside SQL though.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)