排它锁 设table1(A,B,C) A B C a1 b1 c1 a2 b2 c2 a3 b3 c3 新建两个连接 在第一个连接中执行以下语句 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 若同时执行上述两个语句,则select查询必须等待update执行完毕才能执行即要等待30秒
所有查询该记录的sql都加上 select * from tab for update 这样其他查询就会阻塞
排它锁
设table1(A,B,C)
A B C
a1 b1 c1
a2 b2 c2
a3 b3 c3
新建两个连接
在第一个连接中执行以下语句
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 若同时执行上述两个语句,则select查询必须等待update执行完毕才能执行即要等待30秒