uniqueidentifier scope?

  • Hello - When a column is defined as a uniqueidentifier does that mean that the value is unique compared to all other uniqueidentifiers in the database or only for that coluumn? Can a database eventually reach a limit where it runs out of uniqueidentifiers, for example after trillions of records?

  • If identified as a primary key or unique index, a uniqueidentifier will be unique non only on the current database and column, but also across different Systems. Although possible, and it has been documented, it is very unlikely that a uniquefier will be a duplicate.

  • First things first - "uniqueidentifier" is a data type. A column in a table may contain the same value for each and every row in the table (e.g. it could be used as part of a foreign key). The data type by itself does not tell you anything about whether the values you choose to store in the column are unique. That really depends on the logic etc that you use to populate the column

    Now, when you start adding data, you can choose to populate the column with values using application based logic or T-SQL functions such as NEWID () or NEWSEQUENTIALID(). The values returned by the T-SQL functions are supposed to be unique across all servers / databases / tables / columns. I have heard and read that supposedly there are some circumstances when the value generated by these functions are not unique but, so far, I have not found that to be the case.

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

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