What is the difference between Stored Procedure and Trigger in SQL

In this article, we will see the difference between Stored Procedure and Trigger in SQL. Following are the main differences between Stored Procedure and Trigger:

Stored Procedure Trigger
Store Procedures are invoked explicitly Triggers are invoked implicitly
Stored procedure is a user defined piece of code which may return a value (making it a function) that is invoked by calling it explicitly. A trigger is a stored procedure that runs automatically when various events happen (eg update, insert, delete).
We can execute a stored procedure whenever we want Trigger can only be executed whenever an event (insert, delete, and update) is fired on the table on which the trigger is defined
Stored procedure can take input parameters We can’t pass parameters as input to a trigger.
We can use transaction statements like begin transaction, commit transaction, and rollback inside a stored procedure We cant use transaction statements inside a trigger
We can call a stored procedure from the front end We cant call trigger from front end

Leave a Reply

Your email address will not be published. Required fields are marked *