Site icon i2tutorials

MySQL – Triggers

MySQL – Triggers

 

In MySQL, a trigger is a set of SQL statements that are stored in a system catalog. This is a type of stored procedure that is invoked automatically in response to an event. An individual trigger is associated with a table, which is activated by any DML statement, including INSERT, UPDATE, and DELETE.

Triggers are referred to as special procedures because they cannot be called directly like stored procedures. The primary difference between a trigger and a procedure is that a trigger is called automatically when a data modification event occurs against a table. A stored procedure, on the other hand, must be called explicitly.

The SQL standard defines two types of triggers: row-level triggers and statement-level triggers.

Row-Level Trigger:

Triggers are activated by triggering statements such as insert, update, or delete for each row. When multiple rows are inserted, updated, or deleted in a table, the row trigger is automatically invoked for every row affected.

Statement-Level Trigger:

An event trigger fires once for each occurrence of an event on a table, regardless of the number of rows inserted, updated, or deleted.

Limitations of Using Triggers in MySQL

Types of Triggers 

 

Exit mobile version