Tabriz Atayi
Tabriz Atayi

Reputation: 6120

TABLOCK And TABLOCKX definition example

Can someone explain TABLOCKX and TABLOCK keyword and show examples anout this keyword.

What is the functions of these 2 words in queries?

Thank you.

Upvotes: 3

Views: 13315

Answers (2)

elvis
elvis

Reputation: 312

i use the "WITH (TABLOCK)" statement in an insert into an empty clustered table to minimally log the transaction:

INSERT INTO myTable WITH (TABLOCK)
(Column1, Column2...)
SELECT X, Y from Z

Upvotes: 3

user596075
user596075

Reputation:

TABLOCK obtains a shared lock, and TABLOCKX obtains an exclusive lock.

Here's an example of both:

select *
from yourtableSharedLock
with (tablock)

select *
from yourtableExclusiveLock
with (tablockx)

Upvotes: 0

Related Questions