Home » Difference between stored procedure and trigger in SQL

Difference between stored procedure and trigger in SQL

  • by

In this post, you will understand the difference between the stored procedure and trigger.

Stored Procedure

The stored procedure has contained a collection of SQL pre-compiled statements to perform the specific task.

Stored Procedure Syntax

CREATE PROCEDURE Procedure_Name
AS
sql_statements
GO;

Trigger

The trigger is a special kind of store procedure, it invokes only when some events occur in the table, such as Insert, Update, and Delete.

Trigger Syntax

CREATE TRIGGER [schema_name.]trigger_name
ON table_name
AFTER  {[INSERT],[UPDATE],[DELETE]}
[NOT FOR REPLICATION]
AS
{sql_statements}

Difference between stored procedure and trigger

ProcedureTrigger
Procedure explicitly invoke by using commands like execute Trigger implicitly invoke when an event occurs in the table, events such as Insert, Update, and delete
The transaction statement, we can add in the stored procedure The transaction statement we can’t add in the Trigger
Stored Procedure can take input parameters We can’t pass input parameters to the trigger
Stored Procedure can return the output or values Trigger can’t return the values
We can call one stored procedure from another procedure – Nesting ProcedureFrom one trigger we can’t call another trigger – Nesting trigger is not possible

Need help?

Read this post again, if you have any confusion or else add your questions in Community

Tags: