Reputation: 4295
I can't seem to find a straight answer on what should be a simple question. If I create a transaction in T-SQL and set the ISOLATION LEVEL to SERIALIZABLE, does this create a READ lock on the tables that I am modifying?
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
GO
BEGIN TRANSACTION;
GO
TRUNCATE TABLE TBL_PRODUCTS;
GO
**INSERT RECORDS HERE**
GO
COMMIT TRANSACTION;
GO
Upvotes: 3
Views: 2513
Reputation: 980
TRUNCATE TABLE
will acquire a exclusive schema modify lock on the table preventing all users from reading from the table (unless they use and writing to the table (no exceptions for writing). The exclusive lock will be released at TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
or WITH(NOLOCK)
)COMMIT TRANSACTION
.
EDIT: As Martin Smith pointed out in his comment presented below the truncate table will acquire a schema modify lock. Meaning there are no other user will be able to read or modify the table whatsoever until a commit or rollback has taken place.
Upvotes: 1
Reputation: 12318
Yes, it will lock the table, and these are the rules for serializable:
https://msdn.microsoft.com/en-us/library/ms173763.aspx
Upvotes: 2