www.webdeveloper.com
Results 1 to 4 of 4

Thread: what's better? NULL or empty text?

  1. #1
    Join Date
    Mar 2010
    Posts
    281

    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?

    thank you,

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,616
    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...
    Code:
    SELECT * FROM foo WHERE bar IS NOT NULL ORDER BY something
    ...versus...
    Code:
    SELECT * FROM foo WHERE bar != '' ORDER BY something
    (Even though the 2nd version takes fewer keystrokes, for some reason the first seems clearer and more semantically correct to me.)

    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

    eBookworm.us

  3. #3
    Join Date
    Nov 2012
    Location
    Jakarta
    Posts
    42
    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.

  4. #4
    Join Date
    Mar 2010
    Posts
    281
    belated thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles