Wednesday, May 23, 2012

Default size for VARCHAR

What is the output of this statement?
select cast('abcdefghijklmnopqrstuvwxyz1234567890' as varchar)

It's
abcdefghijklmnopqrstuvwxyz1234

Why?
Because, CAST uses a default size of 30 for varchar!
Always make sure you specify the size of your dataypes to avoid such gotchas.

No comments:

Post a Comment