Obtain Update Table Lock at start of Stored Procedure in SQL Server

后端 未结 2 1742
孤城傲影
孤城傲影 2021-01-23 01:44

I\'m writing a SQL Server stored procedure in which I want to lock a table for update before executing the body of the stored procedure. I don\'t want to prevent other processe

2条回答
  •  别那么骄傲
    2021-01-23 02:07

    TABLOCK

    Specifies that a lock is taken on the table and held until the end-of-statement. If data is being read, a shared lock is taken. If data is being modified, an exclusive lock is taken. If HOLDLOCK is also specified, a shared table lock is held until the end of the transaction.

    When used with the OPENROWSET bulk rowset provider to import data into a table without indexes, TABLOCK enables multiple clients to concurrently load data into the target table with optimized logging and locking.

    Taken from: http://msdn.microsoft.com/en-us/library/ms187373(SQL.90).aspx

提交回复
热议问题