I have seen a question on here about this however it was old so I will ask again in case a solution now exists.
My issue is this. I have a database table which I wi
You need to use one of the so-called table hints:
The update lock prevents other processes from attempting to update or delete the rows in question - but it does not prevent read access:
SELECT TOP (20) *
FROM [TMA_NOT_TO_ENTITY_QUEUE] WITH (UPDLOCK)
WHERE [TMA_NOT_TO_ENTITY_QUEUE].[STATE_ID] = 2
ORDER BY TMA_NOT_TO_ENTITY_QUEUE.ID
There's also an exclusive lock, but basically, the update lock should be enough. Once you've selected your rows with an update lock, those rows are "protected" against updates and writes until your transaction ends.