You are on page 1of 8

TRIGGERS

       What are Triggers? Types of Triggers Creating Triggers Implementing Triggers Updating Triggers Deleting Triggers Usage and limitations of Triggers .In This Presentation..

Triggers are special objects that are created on the table and are a part of the database. Triggers a used to enforce data integrity.What are Triggers ?      Triggers are special stored procedures that are created by users and provoked automatically by SQL Server when data modification statements are issues. UPDATE and DELETE statements. . Triggers are invoked in response to INSERT. A trigger can involve any sort of T-SQL statement.

.  INSTEAD OF Triggers are used when a specific action has to be invoked in place of the actual DML operation.Types of Triggers  There   are TWO types of Triggers : FOR Triggers INSTEAD OF Triggers  FOR Triggers are used when a specific action has to be invoked in addition to the actual intended DML operation.

DELETED table contains the values that need to be deleted.Are executed when the DELETE statement is issued against the table. UPDATE Triggers.Are executed when the INSERT statement is issued against the table. INSERTED table contains the new value and DELETED table contains the old value.Are executed when the UDATE statement is issued against the table.Implementation Of Triggers   Triggers are implemented with the help of TWO magic tables : INSERTED and DELETED There are different ways to implement Triggers:    INSERT Triggers. . DELETE Triggers. INSERTED table contains the values that are being inserted.

][UPDATE]} [WITH ENCRYPTION] AS Sql_Statement .][INSERT] [.Creating Triggers CREATE TRIGGER <trigger-name> ON <table-name> FOR | INSTEAD OF { [DELETE] [.

Updating / Dropping Triggers  Triggers are modified using the ALTER command ALTER TRIGGER <trigger-name> <new schema | definition  Triggers are dropped using the DROP command DROP TRIGGER <trigger-name> .

We can disable the Triggers temporarily or permanently. Triggers are slow in execution. Caution needs to be taken to justify their use in OLTP environments. we can control the order in which these triggers are executed. . In case of nested Triggers.Usage and limitations of Triggers     Triggers can be nested.