• Christian Buettner-167247 (4/22/2013)


    Be careful with omitting information in your SQL.

    For example, it is good practice to explicitly specify the nullability of your columns.

    Had ANSI_NULL_DFLT_OFF for the session, the insert would fail.

    Msg 515, Level 16, State 2, Line 9

    Cannot insert the value NULL into column 'IsAvailable', table 'tempdb.dbo.#Test_______________________________________________________________________________________________________________000000000044'; column does not allow nulls. INSERT fails.

    SET ANSI_NULL_DFLT_OFF (Transact-SQL)

    Also, in the CONVERTS, you should specify the size to avoid issues and misunderstandings.

    convert(varchar(30), colxyz)

    instead of

    convert(varchar, colxyz)

    Agreed;

    But if you use session property and check the default value for ANSI_NULLS is always 1. (I guess in production servers this may be the case for some specific SPs or any SQL batch where such explicit usage is needed, but in general it is not necessary, we can just consider the SQL defaults and work with that.)

    and data size mention is good but on the GetDate value it does not effects even if you mention 100 (apart from that, regular varchar/char columns, it is good practice)

    ww; Raghu
    --
    The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.