Skip to content Skip to sidebar Skip to footer

Sql Server: Can Concurrent Threads Update Same Row?

I have a stored proc that has this UPDATE query: UPDATE TOP(1) Batch_tbl SET locked = 1 OUTPUT inserted.batchId INTO #batchId FROM Batch_tbl WHERE locked = 0; It updates the firs

Solution 1:

No. When SQL Server wants to update a row, an UPDATE lock is acquired. This is compatible with other locks, like a shared lock (to read), but it's NOT compatible with another update lock.

So if two concurrent users attempt to update the same row, one of them will "win" and get the UPDATE Lock, while the other user / transaction will have to wait until the first update is done.

Post a Comment for "Sql Server: Can Concurrent Threads Update Same Row?"