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
    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!

By Shannon Lowder

Shannon Lowder is the Database Engineer you've been looking for! Look no further for expertise in: Business Analysis to gather the business requirements for the database; Database Architecting to design the logical design of the database; Database Development to actually build the objects needed by the business logic; finally, Database Administration to keep the database running in top form, and making sure there is a disaster recovery plan.

Leave a comment

Your email address will not be published. Required fields are marked *