时间:2021-07-01 10:21:17 帮助过:16人阅读

更新(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)
标签:blog 忽略 prim 语句 说明 结果 images 删除 ble