How to avoid a database race condition when manually incrementing PK of new row

后端 未结 7 2418
伪装坚强ぢ
伪装坚强ぢ 2020-12-19 08:12

I have a legacy data table in SQL Server 2005 that has a PK with no identity/autoincrement and no power to implement one.

As a result, I am forced to create new rec

7条回答
  •  再見小時候
    2020-12-19 08:54

    The best solution is to change the database. You may not be able to change the column to be an identity column, but you should be able to make sure there's a unique constraint on the column and add a new identity column seeded with your existing PK's. Then either use the new column instead or use a trigger to make the old column mirror the new, or both.

提交回复
热议问题