การสร้างและปรับแต่ง Trigger ใน SQL Server
Florin Angelescu
Instructor

INSERT, UPDATE หรือ DELETECREATE, ALTER หรือ DROPLOGON eventsAFTER trigger
ตัวอย่างการใช้งาน
INSTEAD OF trigger
ตัวอย่างการใช้งาน
-- 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};
การสร้างและปรับแต่ง Trigger ใน SQL Server