Skip to main content

I have two tables with no unique identifer. 

There a two posts that mentions NEWID() as a way to create a unique identifier, so it seems that it can be used:

How to add a default value to a unique identifier field – TimeXtender Support
How to Add a Default Value to a Unique Identifier Field in TimeXtender Classic | Community

I have created a filed in each of my table and made it Primary Key.


My question is:

What happens if we Deoply and Execute on DSA table with a column that creats uniqe id with NEWID()? Does it create new IDs that are different, or does the table keep the IDs generated before?

 

Hi,

do you need a uniqueidentifier or are you essentially making a surrogate key?

Uniqueidentifiers are not deterministic, so you will not get the same one twice for the same record by calling NEWID() . I.e. if you need to redeploy the table you will get new ids for the same records. If you want something deterministic, use a hash field or a supernatural key. It will give you the same varbinary or int for the same business key.

If you really want to use a uniqueidentifier type, then I would make sure the table is a type 1 history table and keep a mapping of business key → uniqueidentifier stored somewhere. Then you can lookup up the unique identifier to your table.