我使用以下代码在我的数据库中打开了快照隔离
ALTER DATABASE MyDatabase
SET ALLOW_SNAPSHOT_ISOLATION ON
ALTER DATABASE MyDatabase
SET READ_COMMITTED_SNAPSHOT ON
Run Code Online (Sandbox Code Playgroud)
并摆脱了许多僵局.
但是当我需要每小时运行一个脚本来清理100,000多行时,我的数据库仍会产生死锁.
我的删除脚本很简单:
delete statvalue
from statValue,
(select dateadd(minute,-60, getdate()) as cutoff_date) cd
where temporaryStat = 1
and entrydate < cutoff_date
Run Code Online (Sandbox Code Playgroud)
现在我正在寻找快速解决方案,但长期解决方案会更好.
非常感谢,Patrikc