Strings and Defaults

  • Nice one Gail. Always good when a question has a twist that's straightforward. (I almost went for 1 and 1, until I remembered ...) Thanks!

    [font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
    Connect to me on LinkedIn

  • Good question, thansk for submitting.

    http://brittcluff.blogspot.com/

  • Good question, which illustrates the importance of defining the maximum data length.

    Thanks,

    Matt

  • One has to wonder at what point will Microsoft add configuration switches (defaulted to force developers to use correct variable declarations) that would allow you to either work with backwards compatibility for things like this versus causing an error because you have not explicitly set the length of your varchar / nvarchar variables for new development projects. IMHO, continuing to allow syntax such as this just allows old habits to continue to live on without indicating that you have code that really needs to be addressed.

  • You would have gotten me if one of the answers was

    123456789012345678901234567890 and

    123456789012345678901234567890

    but without that I had to dig a bit deeper.

    Good question, thanks.

  • You mean like option 4?

    123456789012345678901234567890 and 123456789012345678901234567890

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Loved the question and got it right because I had issues with some old code before.

    Thank you for this straightforward question!

    Best regards,

    Andre Guerreiro Neto

    Database Analyst
    http://www.softplan.com.br
    MCITPx1/MCTSx2/MCSE/MCSA

  • Nice question. And this is why we always declare lengths for variable data types.

  • I knew about VARCHAR defaulting to length of 1, but I learned today about the CASE/CAST 30 byte truncation.

    So.

    Anyone know why MS created two different default data lengths? It seems like redundant inconsistency....

    Rich

  • Who knows. The cause of this is likely buried somewhere in the past.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • KWymore (1/26/2012)


    Nice question. And this is why we always declare lengths for variable data types.

    Agreed

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • I think I chose the right answer and still got it wrong. Is there a way I can confirm which answer I chose?

    Thank you,

    GG.

    "El" Jerry.

    "A watt of Ottawa" - Gerardo Galvan

    To better understand your help request, please follow these best practices.[/url]

  • I was not aware of this. Definatly will keep this in mind for the future.

  • tks for the question.

  • I always declare the length so I wasn't sure what the defaults were but assumed that was what the question was about.

    Good question.

Viewing 15 posts - 16 through 30 (of 47 total)

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