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
2条答案
按热度按时间zaq34kh61#
TRUNCATE TABLE
will acquire a exclusiveschema modify lock on the table preventing all users from reading from the table (unless they useTRANSACTION ISOLATION LEVEL READ UNCOMMITTED
orWITH(NOLOCK)
) and writing to the table (no exceptions for writing). The exclusive lock will be released atCOMMIT 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.
a8jjtwal2#
Yes, it will lock the table, and these are the rules for serializable:
https://msdn.microsoft.com/en-us/library/ms173763.aspx