当查询条件为非主键字段时,为什么在SQLServer的更新锁(UPDLOCK)会锁表
大家能不能帮我看看,当查询条件为非主键字段时,为什么在SQLServer的更新锁(UPDLOCK)会整表锁定?
===========================================================
当我采用主键au_id列作为查询条件时,可以正常锁定查询的行:
begin tran
select * from authors with(updlock) where au_id=1
update authors set au_lname='aaa' where au_id=1
waitfor delay '00:00:30'
commit tran
update authors set au_lname='aaa' where au_id=1
update authors set au_lname='aaa' where au_id=1
begin tran
select * from authors with(updlock) where au_lname='White'
update authors set au_lname='bbb' where au_lname='White'
waitfor delay '00:00:30'
commit tran
update authors set au_lname='bbb' where au_lname='White'
update authors set au_lname='bbb' where au_lname='Green'