Sql Server Transaction Isolation Level
2017-05-09 18:30
477 查看
并发事务引起的问题 | |||
问题 | 描述 | 结果 | 解决 |
丢失更新 | A读—B读—A改—B改 | A更改丢失 | READ UNCOMMITTED |
脏读 | A改—B读—A回滚 | B读无效值 | READ COMMITTED |
不可重读 | A读—B改—A读 | A读不一致 | REPEATABLE READ |
不可重读 | A读—B改—A读 | A读不一致 | SNAPSHOT |
幻读 | A读—B增删—A读 | A读或多或少 | SERIALIZABLE |
1. Read Uncommitted, you might read the data that changed within the scope of another transaction but later being rolled back.
2. Read Committed, you read the latest data at a cost of wait until the transaction that update the records you read completed.
3. Repeatable Read, you read the data and also block the other transaction that write to the same rows of data until your transaction is committed.
4. Snapshot, you read the data and NOT blocking other transaction that change the same rows of data, at a cost of versioning the data rows you read into a temp db, if there are any change to the same data rows, your transaction will be forced to roll back and need to be re-processed.
5. Serializable, the strictiest isolation level that lock the whole table when you read the data and prevent any insert or deletion of the table rows you are querying.
Transaction deadlock are caused by the transaction that wait for other transaction finish execution has timeout, a chosen victim is picked by the system.
Key to mitigate deadlock is reduce the time for reading and writing data and release the lock on the impacted data rows. adding non-cluster index and optimize the sql statement can be options.
Further reading:
http://stackoverflow.com/questions/4034976/difference-between-read-commit-and-repeatable-read
https://msdn.microsoft.com/en-us/library/tcbchxcb(v=vs.110).aspx
Persistimic lock - Read Committed cannot resolve the issue of NOT ABLE TO REPEATABLE READ
Optimstic lock - leverage a added column for version in data table.
相关文章推荐
- SQLServer Transaction Isolation Level
- SET TRANSACTION ISOLATION LEVEL (Transact-SQL)
- SET TRANSACTION ISOLATION LEVEL (Transact-SQL)
- [转]SET TRANSACTION ISOLATION LEVEL (Transact-SQL)
- [转]SET TRANSACTION ISOLATION LEVEL (Transact-SQL)
- SET TRANSACTION ISOLATION LEVEL (Transact-SQL)
- SET TRANSACTION ISOLATION LEVEL 详解
- SET Transaction Isolation Level Read语法的四种情况
- 关于transaction(C#/SQL-Server)
- 关于transaction(C#/SQL-Server),批量处理数据
- 关于transaction(C#\SQL-Server)
- 数据库中的事务处理详解SQL Server Transaction
- 如何解决sql连接错误HResult 0x2, Level 16, State 1 Could not open a connection to SQL Server [2].
- How to view SQL Server Transaction Log
- SET TRANSACTION ISOLATION LEVEL
- A High Level Comparison Between Oracle and SQL Server - Part II
- 关于transaction(C#\SQL-Server)
- Understanding How Transaction are Applied in Transactional Replication in SQL Server 2005
- Setting the IsolationLevel using the System.Transactions TransactionScope
- sql server try catch and transaction的几个要点