Monday, 17 December 2012

Difference between Stored procedures and Triggers

Stored Procedures
Triggers
A Stored procedure is a precompiled set of Structured Query Language (SQL) statements with an assigned name and stored in the server database.
Triggers are SQL procedures that initiate an action when any event occurs. It is associated with a particular table. The events could be insert, update or delete.
We need to call procedures explicitly.
Triggers are implicitly executed.
Stored procedure improves performance and reduces network traffic.
Triggers are used to maintain the referential integrity of data by changing the data in a systematic fashion.
It is helpful in controlling access to data (end-users may enter or change data but do not write procedures), preserving data integrity (information is entered in a consistent manner), and improving productivity (statements in a stored procedure only need to be written one time).
DBMS automatically fires the trigger as a result of data modification to the associated table. It can also execute stored procedures.