July 19, 2010 at 11:36 pm
thanks, this explains everything...:-)
DECLARE @Testvar VARCHAR;
SET @Testvar = 'Red';
print @Testvar;
July 20, 2010 at 8:31 am
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.
July 20, 2010 at 9:07 am
Excellent question. Defaults are always something to keep in mind and to avoid relying on, as they may change.
July 20, 2010 at 10:34 am
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
July 26, 2010 at 5:43 pm
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
July 28, 2010 at 5:47 am
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 ')
August 17, 2010 at 1:03 am
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.
March 7, 2012 at 3:15 pm
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