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!