首页 > 数据库技术 > 详细

sql With(NoLock),With(ReadPast)

时间:2017-09-26 17:09:54      阅读:272      评论:0      收藏:0      [点我收藏+]
---------------
create table tmp1
( 
    id int primary key,
    name nvarchar(20)
)

-----------
insert into tmp1(id,name) values(1,zhsan1);
insert into tmp1(id,name) values(2,lisi1);

-------------------------------
select * from tmp1

技术分享


 

更新(Update)语句对数据库加锁

-----------------------------
begin tran tran1
    update tmp1 set name=zhsan where id=1
-------------------------------
select * from tmp1

查询一直在进行,此时表已经被锁住了

-------------------------------
update tmp1 set name=lisi where id=2
-------------------------------
select * from tmp1 where id>1

技术分享

-------------------------------
delete from tmp1 where id=2
-------------------------------
select * from tmp1 where id>1

技术分享

查询,更新,删除除被锁定的那行数据都能成功,说明被锁住的只有id=1的那一行,对其他行的查询,更新及删除无影响

插入语句

-------------------------------
insert into tmp1(id,name) values(3,lisi)
-------------------------------
select * from tmp1 where id>1

技术分享

结果执行成功,说明插入不受影响


 先将数据库还原为

技术分享

-----------------------------
begin tran tran1
    update tmp1 set name=zhsan where id=1

with(readpast)与with(nolock)

-------------------------------
select * from tmp1 with(readpast)

技术分享

-------------------------------
select * from tmp1 with(nolock)

技术分享

with(readpast)会忽略被锁住的那一行,with(nolock)不会

sql With(NoLock),With(ReadPast)

原文:http://www.cnblogs.com/zhyue93/p/sql_nolock_readpast.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!