SQL Server Performance

unique identifier

Discussion in 'Getting Started' started by RVG, Feb 7, 2010.

  1. RVG Member

    hi,can anyone tell me how unique identifier differs from primary key, please.Thanks & Regards,Ravi Varma
  2. Adriaan New Member

    Personally, I never use uniqueidentifier, but ...
    Uniqueidentifier is a data type, and primary key is a constraint. You will not find a place in a database where you can choose between the two, so there's no point in asking about differences.
    I guess the best suggestion is to learn about both data types and constraints separately, and then see how you would use them in a database.
  3. FrankKalis Moderator

    To add to Adriaan: A column of type uniqueidentifier may be used as PRIMARY KEY. However, despite the name does not automagically create unique values for you. You have to ensure that the values stored in such a column are really unique. Usually you do this via calling NEWID() (or NEWSEQUENTIALID()) in T-SQL, or calls to some application API.
  4. Madhivanan Moderator

    <<
    However, despite the name does not automagically create unique values for you.
    >>
    From BOL
    Creates a unique value of type uniqueidentifier.
  5. FrankKalis Moderator

    Hm, that should read: "However, despite the name does SQL Server not...". Only if you take an additional step like creating a DEFAULT constraint with NEWID() on that column, then is SQL Server automagically taking care of generating values. That's what I meant.
  6. Madhivanan Moderator

    [quote user="FrankKalis"]
    Hm, that should read: "However, despite the name does SQL Server not...". Only if you take an additional step like creating a DEFAULT constraint with NEWID() on that column, then is SQL Server automagically taking care of generating values. That's what I meant.
    [/quote]
    Thanks [:)]

Share This Page