SELECT FOR UPDATE with SQL Server

后端 未结 18 2232
自闭症患者
自闭症患者 2020-11-27 11:49

I\'m using a Microsoft SQL Server 2005 database with isolation level READ_COMMITTED and READ_COMMITTED_SNAPSHOT=ON.

Now I want to use:

18条回答
  •  無奈伤痛
    2020-11-27 12:33

    How about trying to do a simple update on this row first (without really changing any data)? After that you can proceed with the row like in was selected for update.

    UPDATE dbo.Customer SET FieldForLock = FieldForLock WHERE CustomerID = @CustomerID
    /* do whatever you want */
    

    Edit: you should wrap it in a transaction of course

    Edit 2: another solution is to use SERIALIZABLE isolation level

提交回复
热议问题