Click here to Skip to main content
11,494,407 members (71,179 online)
Click here to Skip to main content

Tagged as

Differences between a Stored Procedure and a Trigger

, 22 Jul 2013 CPOL 52.5K 12
Rate this:
Please Sign up or sign in to vote.
Differences between a stored procedure and a trigger.

Differences between a Stored Procedure and a Trigger

  1. We can execute a stored procedure whenever we want with the help of the exec command, but a trigger can only be executed whenever an event (insert, delete, and update) is fired on the table on which the trigger is defined.
  2. We can call a stored procedure from inside another stored procedure but we can't directly call another trigger within a trigger. We can only achieve nesting of triggers in which the action (insert, delete, and update) defined within a trigger can initiate execution of another trigger defined on the same table or a different table.
  3. Stored procedures can be scheduled through a job to execute on a predefined time, but we can't schedule a trigger.
  4. Stored procedure can take input parameters, but we can't pass parameters as input to a trigger.
  5. Stored procedures can return values but a trigger cannot return a value.
  6. We can use Print commands inside a stored procedure for debugging purposes but we can't use print commands inside a trigger.
  7. We can use transaction statements like begin transaction, commit transaction, and rollback inside a stored procedure but we can't use transaction statements inside a trigger.
  8. We can call a stored procedure from the front end (.asp files, .aspx files, .ascx files, etc.) but we can't call a trigger from these files.
  9. Stored procedures are used for performing tasks. Stored procedures are normally used for performing user specified tasks. They can have parameters and return multiple results sets.
  10. The Triggers for auditing work: Triggers normally are used for auditing work. They can be used to trace the activities of table events.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

No Biography provided

Comments and Discussions

 
GeneralMy vote of 4 Pin
Member 1001889423-Jun-14 20:36
memberMember 1001889423-Jun-14 20:36 
GeneralMy vote of 4 Pin
Andrea Quaglia1-Sep-13 2:45
memberAndrea Quaglia1-Sep-13 2:45 
GeneralMy vote of 4 Pin
AlexCode23-Jul-13 23:03
professionalAlexCode23-Jul-13 23:03 
GeneralMy vote of 5 Pin
Member 1013798523-Jul-13 11:18
memberMember 1013798523-Jul-13 11:18 
GeneralMy vote of 4 Pin
Mohammed Hameed22-Jul-13 20:59
professionalMohammed Hameed22-Jul-13 20:59 
GeneralMy vote of 5 Pin
Brian A Stephens22-Jul-13 10:32
professionalBrian A Stephens22-Jul-13 10:32 
GeneralMy vote of 5 Pin
Bhupendra Kumar Shukla22-Jul-13 9:00
memberBhupendra Kumar Shukla22-Jul-13 9:00 
GeneralRe: My vote of 5 Pin
Kulamani Sahoo22-Jul-13 9:48
memberKulamani Sahoo22-Jul-13 9:48 
GeneralRe: My vote of 5 Pin
Bhupendra Kumar Shukla22-Jul-13 9:51
memberBhupendra Kumar Shukla22-Jul-13 9:51 
GeneralRe: My vote of 5 Pin
Kulamani Sahoo22-Jul-13 9:53
memberKulamani Sahoo22-Jul-13 9:53 
GeneralRe: My vote of 5 Pin
Bhupendra Kumar Shukla22-Jul-13 10:01
memberBhupendra Kumar Shukla22-Jul-13 10:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 22 Jul 2013
Article Copyright 2013 by Kulamani Sahoo
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid