CAST

  • Comments posted to this topic are about the item CAST

  • Interesting, I didn't know that.

    Just for fun I just created a dummy table with a VARCHAR column that I didn't specify the length for, and it made it of length 1.

    The Redneck DBA

  • Jason Shadonix (5/20/2009)


    Interesting, I didn't know that.

    Just for fun I just created a dummy table with a VARCHAR column that I didn't specify the length for, and it made it of length 1.

    That's expected for both CHAR and VARCHAR, according to the Books Online when the length is not given the default is 1 during definition and 30 when casting.

    http://msdn.microsoft.com/en-us/library/aa258242(SQL.80).aspx

  • I didn't know that either. I kept thinking the default length when creating a table using the designer is 50. I knew that answer was too easy... 🙂

    Not very good consistency... 3 (50, 30, or 1) different default lengths depending on how you are creating the field.

  • Good question, and good to know. I answered 1 because that's the length you get when you declare a string as varchar without a length. I'm surprised at the inconsistency but glad to be made aware of it.

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills

  • Good question. Never knew that.

    SQL DBA.

  • good and easy one....

    thanks 🙂

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

Viewing 7 posts - 1 through 6 (of 6 total)

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