VARCHAR datatype

  • thanks, this explains everything...:-)

    DECLARE @Testvar VARCHAR;

    SET @Testvar = 'Red';

    print @Testvar;

  • Excellent question! I don't think it's so much about relying on a default (bad practice) so much as forgetting to specify the length, which may not result in a syntax error, and may return results which are incorrect.

    Thanks for the reality check.

  • Excellent question. Defaults are always something to keep in mind and to avoid relying on, as they may change.

  • Good question, got it wrong. Didn't know about default length being set to 1 if not declared. Nice job!

    =============================================================
    /* Backups are worthless, Restores are priceless */

    Get your learn on at SQL University!
    Follow me on Twitter | Connect on LinkedIn
    My blog: http://sqlchicken.com
    My book: Pro Server 2008 Policy-Based Management

  • Good question. I got it wrong, because I didn't notice that the length wasn't specified. That will teach me not to skim read code when working out what it does (something I've often told others they must not do, but am still stupid enough to do it myself).

    Tom

  • Good question! I was shocked to see the four rows when I tried the query!

    Leaving aside the issue of the COLLATION, I opted for the one row answer, because the first that came to mind was the default value of varchar in the CONVERT function, which is 30.

    select convert (varchar, '123456789012345678901234567890123456789012345678901234567890 ')

  • Because all colors are in proper case one can be led to believe that case sensitivity is a factor. To avoide this confusion it would be better to have all colors in lower or upper case.

  • Nice and interesting question.

Viewing 8 posts - 31 through 37 (of 37 total)

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