views:

30

answers:

2
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)

What's wrong?

UPDATE Thanks @codeulike for your help. I put correct trigger t-sql to an answer.

+2  A: 

Assuming you have an ID column:

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]
Mark PM
Thanks mark, you're right. a few changes needed to be work.
Sadegh
A: 
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]
Sadegh