Friday, July 1, 2011

What are the various uses of database triggers ?

SQL Server Books Online states that 
"Triggers are a special class of stored procedure defined to execute automatically when an UPDATE, INSERT or DELETE statement is issued against a table or view."

A trigger is a special type of stored procedure that is not called directly by a user. When the trigger is created, it is defined to execute when a specific type of data modification is made against a specific table or column. Trigger is used when you want to perform a action at a particular point of time. Triggers are used to enforce security constraint.

Triggers help in maintaining consistent,reliable,and correct data in tables. They enable the performance of complex actions and cascade these actions to other dependent tables.

Triggers are automatic executable statement. Triggers are a special kind of procedure. The Main advantage of the trigger is automatic. Whenever the table affected by inserts update or delete 

Query that time the triggers will implicitly call. Its basic advantage is that we don't need to invoke it again and again it will be created once and serve us for the rest of time. Triggers are not Invoked from the Application end rather it will be invoked from the Database Management System. Triggers are used to simply make a look on any of the activity going on the client side.

The problem with triggers is that they cannot be "seen." It is easy to view table relationships, constraints and indexes in the database. On the client-application side, it is also simple to analyze the code. On the other hand, triggers are automatic programs defined in the database that execute behind the scenes as part of the command that fired them. It is hard to follow their logic and in time, it is easy to forget about the triggers in SQL Server, especially if they are not well-documented.

No comments:

Post a Comment