We have very some legacy old transactional tables which contains columns Locked
and LockDate
. Only one user can pick a transaction(row) at a time. Whenever user pick a speecfic transaction, we are marking the row Locked=1
so no other user can pick the same transaction(until user save the transaction or we clear the lock after some time). The problem is that under system load, multiple user can pick the same transaction under concurrency. We are doing,
SELECT TOP 1 * FROM TABLE WHERE Locked=0 AND OurConditions
UPDATE TABLE SET Locked=1 WHERE ID=....
How to fix this issue with minimal performance impect on system.