What are the differences between stored procedures and triggers?

Stored procedures are compiled collection of programs or SQL statements that live in the database. A stored procedure can access and modify data present in many tables. Also a stored procedure is not associated with any particular database object. But triggers are event-driven special procedures which are attached to a specific database object say a table. Stored procedures are not automatically run and they have to be called explicitly by the user. But triggers get executed when the particular event associated with the event gets fired. For example in case of a database having say 200 users and the last modified timestamp need to be updated every time the database is accessed and changed. To ensure this one may have a trigger in the insert or update event. So that whenever any insert or update event of the table gets fired the corresponding trigger gets activated and updates the last modified timestamp column or field with the current time. Thus the main difference between stored procedure and trigger is that in case of stored procedure the program logic is executed on the database server explicitly under eth user’s request but in case of triggers event-driven procedures attached to database object namely table gets fired automatically when the event gets fired.

Questions by GeekAdmin   answers by GeekAdmin

Showing Answers 1 - 9 of 9 Answers

manikandan

  • Dec 4th, 2006
 

triggers are in different namespace from other objects like stored procedures

  Was this answer useful?  Yes

Amol Bawane

  • Nov 15th, 2007
 

The basic difference between stored procedure and trigger is stored procedure can call explicitly, but trigger cannot call explicitly.
Genarally trigger are used for Audit and trail. What should be the action perform while or before or after insert, update and delete.
Generally trigger are used for genrate the primary key. Triggers are same as stored procedure only diff is that which mentioned as above.

Thanks and Regards
Amol Bawane

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions