TABLOCKX vs TABLOCK + XLOCK

  • Hi,

    Is there any difference b/w 1 and 2 below?

    1) INSERT MyTable WITH (TABLOCKX) ...

    2) INSERT dbo.[project] WITH (TABLOCK, XLOCK) ...

    Thanks!

  • Accordingly with the official documentation there is no difference:

    TABLOCK
    Specifies that the acquired lock is applied at the table level. The type of lock that is acquired depends on the statement being executed. For example, a SELECT statement may acquire a shared lock. By specifying TABLOCK, the shared lock is applied to the entire table instead of at the row or page level. If HOLDLOCK is also specified, the table lock is held until the end of the transaction.

    XLOCK
    Specifies that exclusive locks are to be taken and held until the transaction completes. If specified with ROWLOCK, PAGLOCK, or TABLOCK, the exclusive locks apply to the appropriate level of granularity.

    TABLOCKX
    Specifies that an exclusive lock is taken on the table.

  • Thank you Evgeny, but does it mean that 

    applying WITH (TABLOCKX) is exactly the same as WITH (TABLOCK, XLOCK) ?

  • TABLOCKX is a shorter version of (TABLOCK, XLOCK).

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply