SQL Server 2008: SELECT FOR UPDATE

前端 未结 4 1250
时光说笑
时光说笑 2021-01-13 23:28

I have seen a question on here about this however it was old so I will ask again in case a solution now exists.

My issue is this. I have a database table which I wi

4条回答
  •  死守一世寂寞
    2021-01-14 00:28

    You should wrap your processes in a transaction, and set the transaction isolation level appropriately (ie: Serializable)

    SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
    BEGIN TRAN
         UPDATE yourtable...
         -- process 1
    COMMIT TRAN
    

    and

    SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
    BEGIN TRAN
         UPDATE yourtable...
        -- process 2
    COMMIT TRAN
    

    This behaviour has been in SQL Server since time immemorial.

    Other transaction isolation levels are available.

提交回复
热议问题