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

后端 未结 7 2388
伪装坚强ぢ
伪装坚强ぢ 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 09:14

    Create an auxiliary table with an identity column. In a transaction insert into the aux table, retrieve the value and use it to insert in your legacy table. At this point you can even delete the row inserted in the aux table, the point is just to use it as a source of incremented values.

    0 讨论(0)
提交回复
热议问题