1

I want to create a trigger that will update the column LastActivityDate to the current date when the Description column is updated, the problem is that all the rows are being updated, and I don't know how to make the where clause inside the trigger...

I need to make a trigger like this for other tables as well, like the Votes table...

I have:

CREATE TRIGGER test ON Articles
FOR INSERT, UPDATE  
AS
IF UPDATE(Description)
UPDATE Articles SET LastActivityDate = GETUTCDATE()

How would the where clause be?

1 Answer 1

4

You can join to the inserted table to limit the update to the rows updated .

  CREATE TRIGGER test ON Articles
    FOR INSERT, UPDATE  
    AS
    IF UPDATE(Description)
    UPDATE a
    SET a.LastActivityDate = GETUTCDATE()
    from Articles a
    inner join inserted i
    on a.SomeIDField = i.SomeIDField
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.