我正在尝试在有人查看页面时更新表中的一行(它会增加查看次数),但是有时我会遇到死锁错误,我猜这是由于两个或更多人试图更新同一行?
错误是:
Transaction (Process ID 60) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
我的 SQL 是:
UPDATE [ProductDescription]
SET [ViewCount] = ([ViewCount] + 1)
WHERE ProductCode = @prodCode
AND ApplicationID = @AppID
我相信我可能需要一个 WITH(NOLOCK)?