SQL 标准定义的四个事务隔离级别为:
1.Read Uncommitted ( 未提交读 )
可以读取其它事务修改但未提交的数据,但是会导致”脏读”、”幻读”和”不可重复读取”。
2.Read Committed (提交读)
只能读取其它事务修改并已经提交的数据。避免了”脏读取”,但不能避免”幻读”和”不可重复读取”。提交读是大多数主流数据库的默认事务等级。
3.Repeatable Read (可重复读)
锁定已读取的数据,在提交当前事务之前,不允许修改其他事务。它避免了“脏读”和“不可重复读”,但不能避免“幻读”,但带来了更多的性能损失。
[En]
Lock the data that has been read, and other transactions are not allowed to be modified before the current transaction is committed. It avoids “dirty reading” and “non-repeatable reading”, but can not avoid “phantom reading”, but brings more performance loss.
4.Serializable (可串行化)
在读取之前锁定所有要读取的数据,在提交当前事务之前不允许修改其他事务。在最严格的级别上,事务按顺序执行,并且消耗最多的资源。
[En]
Lock all data to be read before reading, and other transactions are not allowed to modify until the current transaction is committed. At the most stringent level, transactions are executed serially and consume the most resources.

脏读:所谓的脏读,其实就是读到了别的事务回滚前的脏数据。比如事务B执行过程中修改了数据X,在未提交前,事务A读取了X,而事务B却回滚了,这样事务A就形成了脏读。
不可重复读:事务A首先读取了一条数据,然后执行逻辑的时候,事务B将这条数据改变了,然后事务A再次读取的时候,发现数据不匹配了,就是所谓的不可重复读了。
幻读:事务A首先根据条件索引得到N条数据,然后事务B改变了这N条数据之外的M条或者增添了M条符合事务A搜索条件的数据,导致事务A再次搜索发现有N+M条数据了,就产生了幻读。
Original: https://www.cnblogs.com/badboy200800/p/12860162.html
Author: 李子恒
Title: 【数据库】SQL标准定义的四个事务隔离级别
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/34900/
转载文章受原作者版权保护。转载请注明原作者出处!