I need to execute a store procedure which includes 3 queries referring to the same table:
MERGE …
SELECT X FROM TABLE WHERE { BLA BLA }
UPDATE Y FROM TABLE WHERE { BLA BLA }
The store procedure should be thread safe and should executed as an atomic operation.
Currently I am using a transaction with serializable isolation level and a WITH ( XLOCK, TABLOCK ) hint on every query.
Is there a way to sustain a table lock for the time span of the store procedure without using a transaction which causing a performance penalty?
Cheers,
Doron
Whenever a developer chooses TABLOCKX or (XLOCK, TABLOCK) it had instantaneously lost the right to ask questions about performance.
Is not the transaction that is causing performance penalties. Is holding the locks. So your question really is:
The answer is no, there is not such way.