What data type

  • Hi all, happy new belated year.

    I have the need to store text/number in a column in MSSQL DB but I not sure which data type would be best. I have found that having a fixed length works but also waste's alot of space, text is the same. If the length varies which data type would yuo suggest to use.

    Jay

  • varchar() or nvarchar()

    ______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience

  • varchar() or nvarchar()

    varchar(max) or varchar(x) is there no variable field, as varchar(50) will always use 50 spaces or however you call them.

    This does seem a really noob question and I apologize

    Jay

    thanks

  • jerome.morris (1/18/2013)


    s varchar(50) will always use 50 spaces or however you call them.

    No it doesn't.

    Char(50) always uses 50 bytes, varchar(50) uses as much space as the data in it (plus a 2 byte overhead), so if you have 10 characters in a varchar(50) column, that takes 12 bytes to store. Varchar is the variable length column type.

    Varchar(max) is for when you're storing over 8000 characters in a column (up to 2.1 billion)

    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
  • GilaMonster (1/18/2013)


    jerome.morris (1/18/2013)


    s varchar(50) will always use 50 spaces or however you call them.

    Sorry I wasnt stating it does I was unsure. Thanks for your explanation

    Jay

Viewing 5 posts - 1 through 4 (of 4 total)

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