Beruflich Dokumente
Kultur Dokumente
K & Bharat
TRIGGERS
1. What are triggers?
• Triggers are special type of Stored Procedures and execute
automatically (in place of or after data modifications) when
an Update, Insert or Delete statement is issued against a
table or view.
• Triggers can be used to automatically enforce business rules
when data is modified. The difference when compared to a
SP is that it can be activated when data is added or edited or
deleted from a table in a database.
• Triggers can be implemented to extend the integrity-
checking logic of constraints, defaults and rules.
• Till SQL Server 7.0, triggers fire only after the data
modification operation happens. So in a way, they are called
Jan 2007
Complied by John .K & Bharat
post triggers. But in SQL Server 2000 you could create pre
triggers also. (INSTEAD OF triggers.)
• Also check out books online for 'inserted table', 'deleted
table' and COLUMNS_UPDATED()
4. Order of Action.
I. T-SQL Command
II. Inserted then Deleted
III. Instead of Trigger (Since SQL Server 2000)-Only 3 IT per
Table .
IV. Constraints
V. Data gets Inserted
VI. After Trigger - Multiple AT per Table.
7. Syntax
• CREATE TRIGGER - Creates a trigger, which is a special kind of stored
procedure that executes automatically when a user attempts the
specified data-modification statement on the specified table.
Jan 2007
Complied by John .K & Bharat
Jan 2007