Building and Optimizing Triggers in SQL Server
Florin Angelescu
Instructor

INSERT, UPDATE or DELETE statementsCREATE, ALTER or DROP statementsLOGON eventsAFTER trigger
Examples of use cases
INSTEAD OF trigger
Examples of use cases
-- Create the trigger by giving it a descriptive name CREATE TRIGGER ProductsTrigger-- The trigger needs to be attached to a table ON Products-- The trigger behavior type AFTER INSERT-- The beginning of the trigger workflow AS-- The action executed by the trigger PRINT ('An insert of data was made in the Products table.');
-- Create the trigger by giving it a descriptive name
CREATE TRIGGER PreventDeleteFromOrders
-- The trigger needs to be attached to a table
ON Orders
-- The trigger behavior type
INSTEAD OF DELETE
-- The beginning of the trigger workflow
AS
-- The action executed by the trigger
PRINT ('You are not allowed to delete rows from the Orders table.');
CREATE TRIGGER MyFirstAfterTrigger
ON Table1
-- Triggered after
-- the firing event (UPDATE)
AFTER UPDATE
AS
{trigger_actions_section};
CREATE TRIGGER MyFirstInsteadOfTrigger
ON Table2
-- Triggered instead of
-- the firing event (UPDATE)
INSTEAD OF UPDATE
AS
{trigger_actions_section};
Building and Optimizing Triggers in SQL Server