0


0

列Xの変更を追跡し、SQL Serverのトリガーによって列Yの値を更新します
CREATE TRIGGER ChangesTracker on [SearchEngine].[Urls]
FOR UPDATE, INSERT AS
UPDATE [SearchEngine].[Urls]
SET [IsNormalized] = 0
WHERE [AbsoluteUrl] NOT IN or <> or != (SELECT [AbsoluteUrl] FROM INSERTED)

どうしましたか?

*更新*助けてくれて@codeulikeに感謝します。 正しいトリガーt-sqlを答えに入れました。

2 Answer


3


ID列があると仮定します。

CREATE TRIGGER ChangesTracker on [SearchEngine].[Urls]
FOR UPDATE, INSERT AS
UPDATE X
SET X.[IsNormalized] = 0
FROM [SearchEngine].[Urls] X JOIN INSERTED I ON X.id = I.id
WHERE x.[AbsoluteUrl]  != I.[AbsoluteUrl]


0


CREATE TRIGGER [SearchEngine].[ChangesTracker]
ON [SearchEngine].[Urls] FOR UPDATE
AS
    UPDATE [SearchEngine].[Urls]
    SET [SearchEngine].[Urls].[IsNormalized] = 0
    From [Inserted]
    INNER JOIN [Deleted]
    ON [Inserted].[UrlId] = [Deleted].[UrlId]
    WHERE [Inserted].[AbsoluteUrl] != [Deleted].[AbsoluteUrl]