UPDATE Triggers

Last time we discussed triggers, we covered insert triggers. This time we’re doing UPDATE triggers. All the same rules apply to UPDATE triggers that apply to INSERT triggers.

CREATE TRIGGER t_tablename_update
ON TableName
AFTER|FOR|INSTEAD OF UPDATE
AS
    T-SQL code

Just like for the INSERT TRIGGER, we can either run the T-SQL code after the update (and all cascade change) has completed, or we can do the code INSTEAD OF the update.

Remember that AFTER and FOR are synonyms.

During update statements you actually gain access to both the deleted and inserted temporary tables. The deleted table shows the original values in the table, and inserted shows the new values. Using these two tables, you could build logging functions that show you what got changed, and what the values were changed from, and changed to.

That’s pretty much all there is to an UPDATE TRIGGER. If you have any questions, please, let me know. I’m here to help!

Tags:

No comments yet.

Leave a Reply

Notify me of followup comments via e-mail. You can also subscribe without commenting.