1.Read Uncommitted 指定语句可以读取已由其他事务修改但尚未提交的行.最低等级的事务隔离,仅仅保证了读取过程中不会读取到非法数据.
- conn.BeginTransaction(IsolationLevel.ReadUncommitted)
conn.BeginTransaction(IsolationLevel.ReadUncommitted)
- 命令:
- SET TRANSACTION ISOLATION LEVEL Read Uncommitted
命令:
SET TRANSACTION ISOLATION LEVEL Read Uncommitted
2.Read Committed:大多数主流数据库的默认事务等级,保证了一个事务不会读到另一个并行事务已修改但未提交的数据,避免了“脏读取”
- conn.BeginTransaction(IsolationLevel.ReadCommitted)
conn.BeginTransaction(IsolationLevel.ReadCommitted)
- SET TRANSACTION ISOLATION LEVEL Read Committed
SET TRANSACTION ISOLATION LEVEL Read Committed
3. Repeatable Read:保证了一个事务不会修改已经由另一个事务读取但未提交(回滚)的数据。避免了“脏读取”和“不可重复读取”的情况,但是带来了更多的性能损失
- conn.BeginTransaction(IsolationLevel.RepeatableRead)
conn.BeginTransaction(IsolationLevel.RepeatableRead)
- SET TRANSACTION ISOLATION LEVEL Repeatable Read
SET TRANSACTION ISOLATION LEVEL Repeatable Read
4.Serializable:最高等级的事务隔离,上面3种不确定情况都将被规避。这个级别将模拟事务的串行执行。
- conn.BeginTransaction(IsolationLevel.Serializable)
conn.BeginTransaction(IsolationLevel.Serializable)
- SET TRANSACTION ISOLATION LEVEL Serializable
SET TRANSACTION ISOLATION LEVEL Serializable