Trigger:
--------
A trigger is a set of T-SQL statements activated in response to certion actions,such as insert or delete or update.
triggers are used to ensure data integrity before or after performing the data maniplations
therefore trigger is a special kind of stored procedure that executes in response to specific events.
Whenever the Trigger is fired in response to the INSERT,DELETE OR UPDATE statement the sql server create two temparary tables
called "magic tables".The magic table are called INSERTED and DELETED.These are logical tables and are similar in structure
to to the table on which trigger is fired
(or)
A trigger is a special kind of a store procedure that executes in response to certain action on the table like
insertion, deletion or updation of data. It is a database object which is bound to a table and is executed automatically.
You can’t explicitly invoke triggers. The only way to do this is by performing the required action no the table that they
are assigned to.
Depending on the way the triggers are fired ,they can be further categorized as
1.AFTER trigger.
2.INSTEAD OF triggers.
1.AFTER Trigger:
-->The after trigger can be created on any table for insert ,update or delete operation
-->The after Trigger is fired after the execution of DML operation.
-->AFTER trigger is executed when all the constraints and triggers defined on the table are succssfully executed.
2.INSTEAD OF TRIGGERS:
----------------------
These can be used as an interceptor for anything that anyonr tried to do on our table or view.
If you define an Instead Of trigger on a table for the Delete operation, they try to delete rows, and they will not
actually get deleted (unless you issue another delete instruction from within the trigger)
INSTEAD OF TRIGGERS can be classified further into three types as:-
(a) INSTEAD OF INSERT Trigger.
(b) INSTEAD OF UPDATE Trigger.
(c) INSTEAD OF DELETE Trigger.
DELETING THE TRIGGER:
---------------------
DROP TRIGGER TRIG_NAME
DISABLING A TRIGGER:
--------------------
DISABLE TRIGGER TRIGGER_NAME
ON TABLENAME|DATABASE
for more info:
CLICK HERE
No comments:
Post a Comment