uniqueidentifier VS varchar(50)

  • i have a table with 200million rows.

    for some reason, one of the columns was built as varchar(50)

    and contains values of type NEWID().

    now i want to fixex this column type to

    varchar(36) or to uniqueidentifier.

    will this save me space on HD?

    1 more importent thing : i have an index on this column.

  • Changing from VARCHAR(50) to VARCHAR(36) won't save space, but it will help keep people from inserting invalid strings that are 37+ characters into it. If you want to save space, make a UNIQUEIDENTIFIER column and cast the values back to the correct type. UNIQUEIDENTIFIER takes just 16 bytes of space in its native format and you don't have to worry about someone inserting non-GUID values into it since the correct data type won't allow it.

  • I would add, that with very few exceptions, it's always best to store any data as the data type it should be. I frequently see problems with people storing dates as strings, GUID's as strings, dates as numbers... make it the correct data type and you'll cut down on a lot of problems.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 3 posts - 1 through 2 (of 2 total)

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