Triggers

A Trigger is a piece of code that is executed in response to a data modification statement - that is, an insert, update, or delete - and usually ensures consistent behaviour of the database. Each trigger refers to a certain table in the database.

Rudimentary support for triggers has been included beginning with MySQL 5.0.2., and SQLyog provides the functionality to manage them.


Create Trigger

To create a new trigger, switch to the Object browser and select the table to which the trigger refers; then use the menu item Others -> Trigger -> Create Trigger.

Enter the trigger name in the appeared dialog, and SQLyog will generate a trigger template in a separate tab of the SQL Window. Fill the template as necessary for you specifying the trigger event (BEFORE/AFTER INSERT/UPDATE/DELETE). Note that the template contains the command to drop the trigger before its creation is case it already exists.

Use the toolbar buttons or hotkeys to execute the queries. As editor tabs of a special kind are used for triggers creation/alteration, pressing both F5 and Shift+F5 keys leads to execution of all queries present in the SQL window.


Alter Trigger

To alter an existing trigger, select it in the Object browser and use the menu item Others -> Trigger -> Alter Trigger or press F6.

A template for the trigger alteration will appear in a separate tab of the SQL Window. The template is similar to that used to create a trigger; it contains a command to drop the trigger in case it already exists and a command for the trigger re-creation.

Use the toolbar buttons or hotkeys to execute the queries. As editor tabs of a special kind are used for triggers creation/alteration, pressing both F5 and Shift+F5 keys leads to execution of all queries present in the SQL window.


Drop Trigger

To drop an existing trigger, select it in the Object browser and use the menu item Others -> Trigger -> Drop Trigger. Then confirm the operation in the appeared dialog.


Rename Trigger

To rename a trigger, select it in the Object browser and use the menu item Others -> Trigger -> Rename Trigger or simply click its name in the Object browser or press F2. 

Still need help? Contact Us Contact Us