Створення та оптимізація тригерів у SQL Server
Florin Angelescu
Instructor

INSERT, UPDATE або DELETECREATE, ALTER або DROPLOGONТригер AFTER
Приклади використання
Тригер INSTEAD OF
Приклади використання
-- 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};
Створення та оптимізація тригерів у SQL Server