DEV Community

loading...

Answer: SQL Server - How to lock a table until a stored procedure finishes

boyukbas profile image baris ・1 min read

with (tablock, holdlock)

BEGIN TRANSACTION

select top 1 *
from table1
with (tablock, holdlock)

-- You do lots of things here

COMMIT

This will hold the 'table lock' until the end of your current "transaction".

</p>





Lock a table while doing some stuff

Discussion (0)

pic
Editor guide