SQLServer 并发问题 先select再update
SQLServer 并发问题
例如
并发执行以下两个事务
事务1
begin tran
declare @count int =0
select @count=[Count] from test4 where id=1
select @count as count1
waitfor delay '00:00:30' --等待30秒
update test4 set [Count]=@count+1 where id=1
commit tran
事务2
begin tran
declare @count int =0
select @count=[Count] from test4 where id=1 --holdlock人为加锁
select @count as count2
update test4 set [Count]=@count+1 where id=1
commit tran
要求:事务2的count2是事务1中已经update 加1后的数据
怎么在数据库层面解决
试过锁,总是出现死锁的问题
例如
并发执行以下两个事务
事务1
begin tran
declare @count int =0
select @count=[Count] from test4 where id=1
select @count as count1
waitfor delay '00:00:30' --等待30秒
update test4 set [Count]=@count+1 where id=1
commit tran
事务2
begin tran
declare @count int =0
select @count=[Count] from test4 where id=1 --holdlock人为加锁
select @count as count2
update test4 set [Count]=@count+1 where id=1
commit tran
要求:事务2的count2是事务1中已经update 加1后的数据
怎么在数据库层面解决
试过锁,总是出现死锁的问题
...全文
相关推荐
SQLServer锁机制探究
SQlServer中的锁机制,并有示例作为参考。
SQL Server 2000 并发控制
SQL Server 2000 并发控制,SQL Server 2000 并发控制
sqlserver中的事务和锁详细解析
下面小编就为大家介绍一下事务和锁,这大概是数据库中比较难理解的东西了
为什么我们需要在SQL Server里更新锁
告诉我们为什么我们需要在SQL Server里更新锁,需要的朋友可以参考下
浅析Sql server锁,独占锁,共享锁,更新锁,乐观锁,悲观锁
以下是对Sql server锁,独占锁,共享锁,更新锁,乐观锁,悲观锁进行了详细的介绍,需要的朋友可以过来参考下


疑难问题
