Nulls Vs Empty String

  • Which is better to use?

  • Depends on your queries. Also - at one point, an "empty" string was not possible but always had at least one space (seems like that was a default for version 7.0 of MS-SQL).

    Pros for empty strings:

    - There is some benefit to always comparing <string>=<string> which is not possible if some values are potentially null.

    - You don't have to "think" so hard about ordering

    - In some data creation routines, it is easier to designate an empty string than a null.

    Pros to NULL (my personal preference)

    - Can use NULL to be mean "not yet defined" and have all other values mean something.

    - Data creation routines do not need to assure that values are set.

    - It seems more convenient to add null columns to an existing table.

    All - in - all... it is probably up to you. I use NULL.

    Guarddata-

  • Thanks for the info , I also wanted to know from performance and db size point of view. Which is more effecient.

  • That is a rather philosophical question that doesn't have an ultimate answer. I'm inclined to say go with NULL, although NULL require some extra bytes of storage which SQL Server need to handle NULL logic properly.

    Frank

    http://www.insidesql.de

    http://www.familienzirkus.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • allright, time for a different sound:

    avoid NULL where possible

    NULLs are giving you a hard time when comparing and with logical operators. In SQL server it even gets worse because ANSI NULLS on/off changes behavior

    just my 2 dollar cent

  • http://qa.sqlservercentral.com/forum/link.asp?TOPIC_ID=17434

    Frank

    http://www.insidesql.de

    http://www.familienzirkus.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply