أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
A trigger is a special kind of stored procedure that automatically executes when an event occurs in the database server. DML triggers execute when a user tries to modify data through a data manipulation language (DML) event. DML events are INSERT, UPDATE, or DELETE statements on a table or view. These triggers fire when any valid event is fired, regardless of whether or not any table rows are affected.
Two type of Trigger
INSTEAD OF and AFTER,
An INSTEAD OF trigger is the one that is usually associated with a view, and runs on an UPDATE action placed on that view.
An AFTER trigger fires after a modification action has occurred.
Syntax of a Trigger CREATE TRIGGER name ON table [WITH ENCRYPTION] [FOR/AFTER/INSTEAD OF] [INSERT, UPDATE, DELETE] [NOT FOR REPLICATION]ASBEGIN--SQL statements...END
Sample Example CREATE TRIGGER [TRIGGER_ALTER_COUNT] ON [dbo].[tblTriggerExample] FOR INSERT, UPDATEASBEGINEND
A special kind of stored procedure which executed automatically after/instead of a specific event occur in the database