41.8 Triggers
The support for Triggers was added in MySQL
TM v.5.0.2.
A Trigger is procedural code that is automatically executed in response to certain events on a particular table in a database.
Creating a Trigger
To create a Trigger:
- open the ''Server Object List'' (chap. 16);
- expand the ''Tables'' node relating the database which contains the table you want to create the trigger in;
- double click on the table name;
- click on the ''Triggers'' Tab of the ''Table Editor'' (sec. 41.4);
- click the ''Add Trigger'' button (or right click and select the ''Add Trigger'' item from the popup menu);
- use the ''Trigger Editor'' (sec. 41.8.1)
Editing a Trigger
To edit a Trigger:
- open the ''Server Object List'' (chap. 16);
- expand the ''Tables'' node relating the database which contains the table which contains the trigger you want to edit;
- double click on the table name;
- click on the ''Triggers'' Tab of the ''Table Editor'' (sec. 41.4);
- in the triggers' grid select the row relating the trigger you want to edit;
- click on the ''Edit selected Trigger'' button (or double click or right click and select the ''Edit Trigger'' item from the popup menu);
- use the ''Trigger Editor'' (sec. 41.8.1)
Dropping a Trigger
To drop a Trigger:
- open the ''Server Object List'' (chap. 16);
- expand the ''Tables'' node relating the database which contains the table you want to drop the trigger from;
- double click on the table name;
- click on the ''Triggers'' Tab of the ''Table Editor'' (sec. 41.4);
- in the triggers' grid select the row relating the trigger you want to drop;
- click on the ''Drop selected Trigger'' (or right click and select the ''Drop Trigger'' item from the popup menu);
- confirm requested operation.
Multi-Drop of Triggers
To drop a set of Triggers of a Table:
- open the ''Server Object List'' (chap. 16);
- expand the table node relating the database which contains the table you want to drop the triggers from;
- right click on the ''Triggers'' node and select the ''Multi-Drop of Triggers'' item from the popup menu;
- use the ''Multi-Drop Wizard'' (chap. 26).
41.8.1 Trigger Editor
The
Trigger Editor allows you to create, edit and drop triggers.
The ''Editor'' (Fig. 41.57) can be opened from the Table Editor or using the popup menu of the Server Objects List (see the introduction of the sec. 41.8).
See Also:
Figure 41.57:
The Trigger Editor.
|
|
The Editor is divided into several Tabs (''Options'',''Statement'',''SQL'').
You may open as many Trigger Editors as you want to do a comparison between more triggers (of the same or of different servers).
Toolbar
Using the toolbar you may:
-

refresh the ''Editor'';
-

save your changes;
-

drop the current trigger;
-

create a new trigger;
-

load the trigger's statement from a file;
-

save the trigger's statement to a file;
-

undo your changes (just for the ''Statement'' Tab);
-

redo your changes (just for the ''Statement'' Tab);
-

view the help;
-

close the ''Editor''.
41.8.1.1 Options
The ''Options'' Tab (Fig.
41.58) allows you to set the trigger's options (like the Name, Time, Event, Table).
The ''Trigger Information'' frame is not editable; it includes useful information about the trigger.
Figure 41.58:
Trigger Options.
|
|
41.8.1.2 Statement
The ''Statement'' Tab (Fig.
41.59) allows you to edit the trigger statement, i.e. the SQL statements executed when triggering.
You may load the trigger's statement from a file clicking on the ''Load Trigger's Statement from File'' button.
Figure 41.59:
Trigger Statement.
|
|
If you right click a useful popup menu will appear (Fig. 41.60).
Figure 41.60:
Trigger Editor: Popup menu.
|
|
41.8.1.3 SQL
The ''SQL'' Tab (Fig.
41.61) contains the SQL syntax for recreating the current trigger. The code control is not editable: please use the ''Options'' and ''Statement'' Tabs to edit the trigger properties.
If you right click a useful popup menu will appear.
Figure 41.61:
Trigger Syntax.
|
|
Copyright © 2007 - 2009 HoneySoftware - All Rights Reserved
Submit feedback on this topic.