We have a table in which versions of records will be stored.
Columns:
Id (Guid) VersionNumber (int) Title (nvarchar) Description (nvarchar) etc...
Saving an item will insert a new row into the table with the same identifier and incremental version number.
I'm not sure how best to create sequential VersionNumber values. My initial thought:
SELECT @NewVersionNumber = MAX(VersionNumber) + 1 FROM VersionTable WHERE Id = @ObjectId
And then use @NewVersionNumber in my insert statement.
If I use this method, do I need to set my transaction as serializable to avoid concurrency issues? I do not want to duplicate VersionNumbers for the same Id.
Is there a better way to do this that doesn't force me to use serializable transactions?
sql-server tsql
Brownie
source share