我有一個像下面這樣的觸發器,邏輯是在fidRule狀態改變後更改FID狀態。SQL服務器UPDATE TRIGGER不會觸發
在我的應用程序,我更新每行1行, 但我發現有時(非常罕見)觸發器沒有發射。
ALTER TRIGGER [dbo].[triggerSetFIDStatus]
ON [dbo].[FIDRules]
AFTER UPDATE
AS
BEGIN
set nocount on
DECLARE @ruleStatus INT
DECLARE @newRuleStatus INT
DECLARE @FIDAlertStatus INT
DECLARE @FIDId INT
DECLARE @isFIDEnabled int
DECLARE @ruleId INT
SELECT @ruleStatus = deleted.alertStatus,
@FIDId = deleted.FIDID,
@ruleId = deleted.id
from
deleted
SELECT @newRuleStatus = inserted.alertStatus
from
inserted
SELECT @FIDAlertStatus = alertStatus,
@isFIDEnabled= isEnabled
FROM FID
WHERE id = @FIDId
IF @FIDAlertStatus <> @newRuleStatus
BEGIN
-- change FID-status by FIDRule-status
UPDATE [dbo].[FID] SET [email protected] WHERE [email protected]
END
IF @newRuleStatus >= 0 AND @newRuleStatus <> @ruleStatus
UPDATE [dbo].[FIDRules] SET isAlertStatChanged=1, AlertStatChangeTime = SYSUTCDATETIME() WHERE [email protected]
END
您的觸發器是否啓用?檢查'SELECT名稱,is_disabled FROM sys.triggers' –
你的觸發器假設只有一行是一次更新的。 – MartW
@CodeByMoonlight我在每個語句中更新1行 –