Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stored Procedures vs Triggers in MySQL

How are STORED PROCEDURES different than TRIGGERS in the MySQL world ?

like image 598
Hrishikesh Choudhari Avatar asked Nov 13 '10 07:11

Hrishikesh Choudhari


People also ask

What are triggers and stored procedures in MySQL?

A trigger is defined to activate when an INSERT, DELETE, or UPDATE statement executes for the associated table. A stored procedure is a group of Transact-SQL statements compiled into a single execution plan.

Can triggers be used in stored procedure?

A: Yes, we can call stored procedure inside the trigger.

What is the difference between a trigger and stored procedure What are the system tables that can be accessed in a trigger?

What is the difference between Triggers and Stored Procedure? Stored Procedures are called by the programmer wherever it wants to fire but triggers fired automatically when insert,delete,update occured. And triggers can be implemented to tables & views only where as stored procedure used in the database independently.

What is the advantage of stored procedure over the database triggers?

Stored procedures can accept parameters and can return values. Triggers can neither accept parameters nor return values. A Trigger is dependent on a table and the application has no control to not fire a trigger when not needed. On the other hand, a stored procedure can be called as needed.


1 Answers

Stored procedures are stored as precompilated code (stored routine) and called by the programmer wherever it wants to fire. Stored procedure can return value(s). About procedures and functions.

Triggers are named database objects fired automatically when insert, delete, update (or other event) occurred, there can be no explicit invocation. Trigger can not return any data. About triggers.

You can use procedures in trigger's code.

like image 55
ksogor Avatar answered Oct 06 '22 00:10

ksogor