补充上一篇修改用非聚集索引:
update Employee set age=age+1 from Employee with(index=nc_Employee_Age) where age<30
执行计划:
并发访问控制隔离级别:
1.读提交:默认行为,读取时请求S锁
set transaction isolation level read committed
select * from Employee where age=34
2. 脏读:读取时不请求S锁,不会受到其他X锁限制
set transaction isolation level read uncommitted
select * from Employee
3. 已提交快照读:更新时将老的数据复制到 Tempdb:read_committed_snapshot
alter database HRDB
set read_committed_snapshot on
设置成单用户模式:
设置事物:
begin tran
update Employee set age=age+1 where age>=30
执行语句:
select * from Employee
这条语句也可以执行:
select * from Employee where age>30
这条可以执行:
update Employee set age=age+1 from Employee with(index=nc_Employee_Age) where age<30
没有复制的还是从索引或基表中读取。所以可以读取出数据
这条不能执行:
update Employee set age=age+1 from Employee with(index=nc_Employee_Age) where age>30
打开数据库的读提交快照。 对记录进行操作时,会把排他锁的数据放到Tempdb数据库中,访问的时候直接读出Tempdb的数据。
4.可重复读:事物结束前,不释放获取的S锁,可能会形成死锁
create table Products(id int identity(1,1),name varchar(500),UnitPrice money)
delete from Products where id=2
insert Products values ('p1',13)
insert Products values('