DELETE Triggers

This is the last of my three posts on triggers. We’ve already covered INSERT and UPDATE TRIGGERS. This time we’re doing DELETE triggers. All the same rules apply to DELETE triggers that apply to INSERT and UPDATE triggers.

CREATE TRIGGER t_tablename_delete
ON TableName
AFTER|FOR|INSTEAD OF DELETE
AS
    T-SQL code

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

Remember that AFTER and FOR are synonyms.

In INSERT triggers you gained access to the temporary table inserted. During UPDATE triggers, you gained access to the updated table. For deleted triggers, you gain access to deleted. This temporary table is only accessible from the T-SQL code you include in the body of the TRIGGER.

That’s pretty much all there is to an DELETE 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.

1 comment

Leave a comment

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