Here's a SQL UPDATE
command with parameters...
UPDATE MyTable
SET MyField = @newvalue,
@success = 1
WHERE
Id = @id
AND MyField = @oldvalue
Many clients will be running this command with the same @id
and @oldvalue
parameter values at the same time. I want only one of them to be the "winner" and set MyField
to it's own @newvalue
, and for it to know it won because the @success
output parameter will be set to 1.
What's the lowest isolation level needed for this to work and guarantee that only one client will ever "win"? Do I need a transaction for this one statement?
I'm using SQL Server 2008, but I hope there's a standard SQL answer.