并发处理-隔离级别

READ UNCOMMITTED:指定语句可以读取已由其他事务修改但尚未提交的行。

同时执行以下sql语句:

A.--隔离级别-read committed
set transaction isolation level READ COMMITTED
Begin Tran

Update Sys_Items set ItemName='Changed123' where Id=2
WAITFOR DELAY '000:00:15'
commit tran

 

B.
set
transaction isolation level READ UNCOMMITTED select * from Sys_Items where Id=2

B因为是【READ UNCOMMITTED】,所以A还未提交的时候。便已经可以查询出修改后的结果了。

 

READ COMMITTED:指定语句不能读取已由其他事务修改但尚未提交的数据。

 

 

实例1:

 1 --隔离级别-read committed
 2 set transaction isolation level read committed
 3 Begin Tran
 4 
 5 Update Sys_Items set ItemName='Changed' where Id=2
 6 WAITFOR DELAY '000:00:20'
 7 rollback tran
 8 
 9 set transaction isolation level read committed
10 select * from Sys_Items where Id=2
11 
12 --隔离级别-repeatable read
13 set transaction isolation level repeatable read
14 Begin Tran
15 Update Sys_Items set ItemName='Changed' where Id=2
16 WAITFOR DELAY '000:00:20'
17 rollback tran
View Code

实例2:

若同时执行上述两个语句,则select查询必须等待update执行完毕才能执行即要等待30秒

在第一个连接中执行以下语句

begin tran
update table1
set A='aa'
where B='b2'
waitfor delay '00:00:30' --等待30秒
commit tran

在第二个连接中执行以下语句

begin tran
select * from table1
where B='b2'
commit tran

 

转载于:https://www.cnblogs.com/chenze-Index/p/9673521.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值