关于事务隔离级别

隔离级别(isolation level)定义了事务与事务之间的隔离程度。隔离级别与并发性是互为矛盾的:隔离程度越高,数据库的并发性越差;隔离程度越低,数据库的并发性越好。

ANSI/ISO SQL92标准定义了一些数据库操作的隔离级别:
 未提交读(read uncommitted)
 提交读(read committed)
 重复读(repeatable read)
 序列化(serializable)

通过一些现象,可以反映出隔离级别的效果。这些现象有:
1. 更新丢失(lost update):当系统允许两个事务同时更新同一数据时,发生更新丢失。
2. 脏读(dirty read):当一个事务读取另一个事务尚未提交的修改时,产生脏读。
3. 非重复读(nonrepeatable read):同一查询在同一事务中多次进行,由于其他提交事务所做的修改或删除,每次返回不同的结果集,此时发生非重复读。(A transaction rereads data it has previously read and finds that another committed transaction has modified or deleted the data. )
4. 幻像(phantom read):同一查询在同一事务中多次进行,由于其他提交事务所做的插入操作,每次返回不同的结果集,此时发生幻像读。(A transaction reexecutes a query returning a set of rows that satisfies a search condition and finds that another committed transaction has inserted additional rows that satisfy the condition. )

下面是隔离级别及其对应的可能出现或不可能出现的现象:
 

Dirty Read

NonRepeatable Read

Phantom Read

Read uncommitted

Possible

Possible

Possible

Read committed

Not possible

Possible

Possible

Repeatable read

Not possible

Not possible

Possible

Serializable

Not possible

Not possible

Not possible

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值