基本用法
-- Syntax for SQL Server and Azure SQL Database
SET TRANSACTION ISOLATION LEVEL
{ READ UNCOMMITTED
| READ COMMITTED
| REPEATABLE READ
| SNAPSHOT
| SERIALIZABLE }
区别
因为SQL Server Management Studio默认是自动提交的,先改成手动提交。
--manual commit
SET IMPLICIT_TRANSACTIONS ON
SQL Server默认的事务是READ COMMITTED级别,最低的限制是READ UNCOMMITTED,即允许脏读,查询正在update还没提交的数据,是不会触发shared lock的,并且显示已经update的数据。
--read uncommitted, no shared lock
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SQL Server默认的事务级别
--read committed, shared lock(default)
ALTER DATABASE ICHM_DB set READ_COMMITTED_SNAPSHOT OFF
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
SQL Server默认的事务级别的变种,和 READ COMMITTED唯一的区别就是允许脏读,但是读出来的数据是update之前的值,相当于查询出来的是个snapshot值。
--read committed, no shared lock
ALTER DATABASE ICHM_DB set READ_COMMITTED_SNAPSHOT ON
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
参考链接:
官方transaction isolation level说明