SQL Server › Triggers
What is the difference between an AFTER trigger and an INSTEAD OF trigger?
BeginnerAnswer
An AFTER trigger runs once the triggering action, like an insert or update, has already completed, letting you perform additional actions based on the change that just happened, while an INSTEAD OF trigger completely replaces the original triggering action, giving you full control to perform custom logic instead of the default behavior that would have otherwise occurred.
CREATE TRIGGER trg_PreventDelete
ON Orders
INSTEAD OF DELETE
AS
BEGIN
UPDATE Orders SET IsDeleted = 1
WHERE OrderId IN (SELECT OrderId FROM deleted);
END;Real-world example An order system uses an INSTEAD OF DELETE trigger to implement soft deletes, marking orders as deleted with a flag instead of actually removing them from the table, preserving the historical record while still appearing deleted to the application.