为什么,当我SAVE TRAN SavePoint
位于位置 (A) 时,我在第三次陷入 CATCH 及其他情况时会收到这些错误...
“消息 6401,级别 16,状态 1 ...无法回滚 SavePoint。未找到该名称的事务或保存点。”
SAVE TRAN SavePoint;
...但是当位于位置 (B)时我没有收到此类错误?
我只能想象这与光标循环的上下文有关,但我不明白为什么。
-- Premable stuff, opening cursor, etc. here...
BEGIN TRAN
SAVE TRAN SavePoint; -- (A)
WHILE @@FETCH_STATUS = 0
BEGIN;
-- SAVE TRAN SavePoint; -- (B)
BEGIN TRY
-- UPDATE statement here which may fail
SAVE TRAN SavePoint;
END TRY
BEGIN CATCH
ROLLBACK TRAN SavePoint;
END CATCH;
FETCH NEXT FROM Cursor INTO @X, @Y, @Z;
END;
-- CLOSE & DEALLOCATE stuff here
IF @DryRun = 1
ROLLBACK TRAN;
ELSE
COMMIT TRAN;