Hi,
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.
Creating a Trigger:
Syn:
CREATE TRIGGER <trigger_name>
ON {table|View}
{FOR [AFTER] | INSTEAD OF } { INSERT [,DELETE,UPDATE]}
AS
BEGIN
<SQL statements>
END
For:
You can use the FOR clause to specify when a trigger is executed.
AFTER:
The trigger executes after the statement that triggered it completes. If the statement fails with an error, such as a constraint violation or syntax error, the trigger is not executed. AFTER triggers cannot be specified for views, they can only be specified for tables. You can specify multiple AFTER triggers for each triggering action (INSERT, UPDATE, or DELETE). If you have multiple AFTER triggers for a table, you can use sp_settriggerorder to define which AFTER trigger fires first and which fires last. AFTER is the default in SQL Server 2000.
INSTEAD OF:
The trigger executes in place of the triggering action. INSTEAD OF triggers can be specified on both tables and views. You can define only one INSTEAD OF trigger for each triggering action (INSERT, UPDATE, and DELETE). INSTEAD OF triggers can be used to perform enhance integrity checks on the data values supplied in INSERT and UPDATE statements. INSTEAD OF triggers also let you specify actions that allow views, which would normally not support updates, to be Updatable.
Thanks & Regards
Rajamani, if this helps please login to Mark As Answer. | Alert Moderator