SQL Server 2008 - Default column value - should i use null or empty string? -


For some time I am arguing if I should leave the column which I do not know will pass the data and set The value for the empty string will be ('') or just allow zero.

I want to hear what is the recommended practice here.

If it makes a difference, then I am using it as a consumer application.

I'm scared that ...

It depends!

There is no single answer to this question.

As a sign in other reactions, at the level of SQL , NULL and very different words in the empty string , formerly indicating it That value is unknown, later it shows that the value is "invisible thing" (in display and report), but no "known value" is less. An example given in this context is the middle name. A zero value in the "middle_name" column will indicate that we do not know whether the name is or not between the underlying person, and if so what is this name, an empty string will indicate that we know that this person < No is a middle name.

This said, two other types of factors can help you choose between these options for the given column.

  • Li> Strong>
    For example it is important to know whether the empty string is a valid value for the underlying data. If this is the case, then we can clear the information if we also use empty string for "unknown information". Another idea is whether some alternative values ​​can be used in this case, when our There is no information for the nearest column;

    SQL Behavior and Utilities
    Considering SQL behavior, not using the choice of using or using, rather than 'n / a' Or 'unspecified' or 'TBD' are better values. Zero, space can be inspired by thought, by the desire to create a filtered index or by facilitating the COALESCE () function (which can be simulated with the case statement, but in more verbose fashion). Another idea is whether a query might try to query multiple columns to add them (like SELECT name + ',' + middle_name AS LongName etc.).

    String beyond the validity of the choice of zero versus empty, in the given position, try a general idea and be as consistent as possible, that is, try and stick in a special way, and only / deliberately / Clearly depart for good reasons and in some cases.


  • Comments

    Popular posts from this blog

    sql - dynamically varied number of conditions in the 'where' statement using LINQ -

    asp.net mvc - Dynamically Generated Ajax.BeginForm -

    Debug on symbian -