22,210
社区成员
发帖
与我相关
我的任务
分享
begin tran
declare @count int =0
select @count=[Count] from test4 WITH(UPDLOCK,HOLDLOCK) where id=1
select @count as count1
waitfor delay '00:00:30'
update test4 set [Count]=@count+1 where id=1
commit tran
select * from TEST4
begin tran
declare @count int =0
select @count=[Count] from test4 WITH(UPDLOCK,HOLDLOCK) where id=1
select @count as count2
update test4 set [Count]=@count+1 where id=1
commit tran
select * from TEST4
begin tran
DECLARE @t TABLE ([Count] int)
declare @count int =0
-- 都在更新、加锁的同时读取旧值
update test4
set [Count]=[Count]+1
OUTPUT DELETED.[Count]
INTO @t
where id=1
waitfor delay '00:00:30'
SELECT @count = [Count] FROM @t
SELECT @count AS count1
commit tran
SELECT * FROM test4
begin tran
DECLARE @t TABLE ([Count] int)
declare @count int =0
update test4
set [Count]=[Count]+1
OUTPUT DELETED.[Count]
INTO @t
where id=1
SELECT @count = [Count] FROM @t
SELECT @count AS count2
commit tran
SELECT * FROM test4