SQL server: Can concurrent threads update same row?

前端 未结 1 1934
一生所求
一生所求 2021-01-20 03:23

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 =          


        
相关标签:
1条回答
  • 2021-01-20 04:07

    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.

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