以下查询将为我提供运行此命令后立即执行更新所需的 ID 列表:
SELECT TOP 5 WorkflowEventProcessingID
FROM Master.WorkflowEventProcessing
WHERE ProcessingToken IS NULL
ORDER BY WorkflowEventProcessingId
有没有办法在一个选择语句中获取此范围的最小(55034)和最大(55038)ID,所以我可以这样做:
UPDATE WorkflowEventProcessing
SET ProcessingToken = <guid here>
WHERE WorkflowEventProcessingId >= @minId
AND WorkflowEventProcessingId <= @maxId
我尝试过这样的事情,但我已经走了:
DECLARE @minId INT
DECLARE @maxId INT
SELECT TOP 5 @minId = min(WorkflowEventProcessingID), @maxId = MAX(WorkflowEventProcessingID)
FROM Master.WorkflowEventProcessing
WHERE ProcessingToken IS NULL
ORDER BY WorkflowEventProcessingId
编辑
我不想使用子 SELECT 进行更新,因为我遇到了死锁。所以我被告知将 SELECT 和 UPDATE 分开,以便让单独的 DELETE 进程有机会在 UPDATE 和 SELECT 之间运行。