gotqn
gotqn

Reputation: 43666

Using "rowversion" as primary key column

I am using SQL Server 2012 and I want to create a "changes" table - it will be populated with data from other table when the second table columns values are changed.

I am adding to the "changes" table "datatime2", and "rowversion" columns in order to track when the changes are made.

Is it ok to use "rowversion" as primary key?

I have read here that it will be changed, if the current row is updated and that's why it is not a good candidate for "primary key" making foreign keys invalid.

Anyway, if it won't be used as a foreign key and the rows of "changes" table will never be updated (only new rows will be inserted) is it ok to use the "rowversion" as PK or I should use additional column?

Upvotes: 1

Views: 900

Answers (1)

Russell Fox
Russell Fox

Reputation: 5445

Some good info here:

Careful reading of the MSDN page also shows that duplicate rowversion values are possible if SELECT INTO statements are used improperly. Something to watch out for there.

I would stick with an Identity field in the original data, carried over into the change tracking table that has its own Identity field.

Upvotes: 0

Related Questions