简体   繁体   English

TRANSACTION ISOLATION LEVEL SERIALIZABLE是否创建READ锁定

[英]Does TRANSACTION ISOLATIoN LEVEL SERIALIZABLE create READ lock

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? 如果我在T-SQL中创建事务并将ISOLATION LEVEL设置为SERIALIZABLE,这是否在我正在修改的表上创建了READ锁?

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
GO
BEGIN TRANSACTION;
GO    
TRUNCATE TABLE TBL_PRODUCTS;
GO
    **INSERT RECORDS HERE**
GO
    COMMIT TRANSACTION;
GO

TRUNCATE TABLE will acquire a exclusive shema modify lock on the table preventing all users from reading from the table (unless they use TRANSACTION ISOLATION LEVEL READ UNCOMMITTED or WITH(NOLOCK) ) and writing to the table (no exceptions for writing). TRUNCATE TABLE将获得TRUNCATE TABLE 独占 shema修改锁,以防止所有用户从表中读取 (除非他们使用 TRANSACTION ISOLATION LEVEL READ UNCOMMITTEDWITH(NOLOCK)并写入表(写入时没有例外)。 The exclusive lock will be released at COMMIT TRANSACTION . 排他锁将在COMMIT TRANSACTION释放。

EDIT: As Martin Smith pointed out in his comment below the truncate table will acquire a schema modify lock. 编辑:正如马丁·史密斯(Martin Smith)在其truncate表下方的注释中指出的那样,它将获得一个模式修改锁。 Meaning there are no other user will be able to read or modify the table whatsoever until a commit or rollback has taken place. 意味着在进行提交或回滚之前,没有其他用户可以读取或修改表。

Yes, it will lock the table, and these are the rules for serializable: 是的,它将锁定表,这些是可序列化的规则:

  • Statements cannot read data that has been modified but not yet committed by other transactions. 语句无法读取已被其他事务修改但尚未提交的数据。
  • No other transactions can modify data that has been read by the current transaction until the current transaction completes. 在当前事务完成之前,没有其他事务可以修改当前事务已读取的数据。
  • Other transactions cannot insert new rows with key values that would fall in the range of keys read by any statements in the current transaction until the current transaction completes. 在当前事务完成之前,其他事务不能插入键值将落入当前事务中任何语句读取的键范围内的新行。

https://msdn.microsoft.com/en-us/library/ms173763.aspx https://msdn.microsoft.com/en-us/library/ms173763.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 可序列化的事务隔离锁 - serializable transaction isolation lock 可序列化的隔离级别 - 它会阻止读取吗? - Serializable isolation level - does it block read? 具有可序列化隔离级别的事务中的死锁 - Deadlock in transaction with isolation level serializable 事务级别之间的差异:读可写和可隔离级别 - Differences between TRANSACTION's levels: READ WRITE and ISOLATION LEVEL SERIALIZABLE 是否可以在数据库级别设置无锁或“事务隔离级别未提交读”? - Is it possible to set no lock or TRANSACTION ISOLATION LEVEL READ UNCOMMITTED at database level? 可重复读取隔离级别是否锁定所有表以进行更新? - Does repeatable read isolation level lock all table for update? SQL事务隔离级别可序列化与在开发与生产中提交的读取 - SQL Transaction Isolation Level Serializable vs Read Committed in Dev vs Production 归因于隔离级别可序列化的SQL事务失败的一般处理 - Generalized handling of SQL transaction failures due to isolation level serializable “SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED”和观点 - “SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED” and views 如何在 SQL 中创建具有隔离级别的事务 - How to create transaction with isolation level in SQL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM