Triggers
A trigger is another form of executable code that is stored in the metadata of the database for execution by the server.A trigger cannot be called directly.It is called automatically (“fired”) when data-changing events involving one particular table or view occur, or on a specific database or DDL event.
A trigger applies to exactly one table or view or database event, and only one phase in an event (BEFORE
or AFTER
the event).A single DML trigger might be written to fire only when one specific data-changing event occurs (INSERT
, UPDATE
or DELETE
), or it might be written to apply to more than one of those.
A DML trigger is executed in the context of the transaction in which the data-changing DML statement is running.For triggers that respond to database events, the rule is different: for DDL triggers and transaction triggers, the trigger runs in the same transaction that executed the DDL, for other types, a new default transaction is started.