Data Type and Length

  • David Data (9/28/2010)


    OTOH I designed our ETL system with [Postcode] [nvarchar](10) and then had to change it when I found records with postcodes like 'If out please leave by back door or with neighbour at No. 127' 🙁

    I really hope your design change was to add a column for "delivery comments", not to increase the maximum length for the postcode. (Unless your business operates in a country where 'If out please leave by back door or with neighbour at No. 127' is a valid postcode).

    But I do hope you changed the postcode to varchar(10). As far as I know, all countries in the world that use postal codes limit them to numbers and the letters A-Z.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • David Data (9/27/2010)


    But I am curious as to why a VARCHAR(MAX) string that happens to contain say 100 chars is so much slower that a VARCHAR(100) that does? Its index and length values will have to be 32 bit numbers, but with 32/64 bit CPUs anything shorter tends to be less rather than more efficient anyway. As even a VARCHAR(100) is stored as a variable length string, I would not imagine the memory management issues are much different either. Or are they?

    Im not sure. Some folks insist (and maybe rightfully so... I seem to remember such a thing in BOL but don't remember for sure) the VARCHAR(MAX) stays "inrow" under such conditions. To me, it seems like it may not but I've not taken the time to research that to any depth. It would be nice to know for sure but I just don't have the floor space on my dance card right now.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 2 posts - 31 through 31 (of 31 total)

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