为了检索ID,我首先在两个后续查询中进行选择,然后进行更新。
问题是我遇到了锁定行的问题。我读过这两个陈述,……
多个客户端同时访问表counter_list吗?
OLTP的最佳实践是调用将在一个事务中执行更新逻辑的存储过程。
检查表dba.counter_list是否有列table_name的索引。 还要检查它是否已锁定行级别。
假设:
select
counter
考虑以下 update 声明应该消除运行您的多个用户可能发生的任何竞争条件 select/update 逻辑同时:
update
select/update
declare @counter int -- change to the appropriate datatype update dba.counter_list set @counter = counter, -- grab current value counter = :NewCounter -- set to new value where table_name = :TableName select @counter -- send previous counter value to client
无论您是通过SQL批处理还是存储的proc调用提交上述内容,都由您和您的DBA决定...