Stored Procedures, Functions, Triggers, And Last_Insert_Id(); Using Triggers; Trigger Syntax - Oracle 5.0 Reference Manual

Table of Contents

Advertisement

the output of
param_list
18.2.4. Stored Procedures, Functions, Triggers, and
Within the body of a stored routine (procedure or function) or a trigger, the value of
LAST_INSERT_ID()
these kinds of objects (see
trigger upon the value of
the kind of routine:
• If a stored procedure executes statements that change the value of
changed value is seen by statements that follow the procedure call.
• For stored functions and triggers that change the value, the value is restored when the function or
trigger ends, so following statements do not see a changed value. (Before MySQL 5.0.12, the value
is not restored and following statements do see a changed value.)

18.3. Using Triggers

Support for triggers is included beginning with MySQL 5.0.2. A trigger is a named database object that
is associated with a table, and that activates when a particular event occurs for the table. Some uses
for triggers are to perform checks of values to be inserted into a table or to perform calculations on
values involved in an update.
A trigger is defined to activate when an INSERT, DELETE, or
associated table. A trigger can be set to activate either before or after the triggering statement. For
example, you can have a trigger activate before each row that is inserted into a table or after each row
that is updated.
To use triggers if you have upgraded to MySQL 5.0 from an older release that did not support
triggers, you should upgrade your grant tables so that they contain the trigger-related privileges. See
Section 4.4.9,
The following discussion describes the syntax for creating and dropping triggers, and shows some
examples of how to use them.
Additional Resources
• You may find the
• For answers to some commonly asked questions regarding triggers in MySQL, see
"MySQL 5.0 FAQ:
• There are some restrictions on the use of triggers; see
Programs".
• Binary logging for triggers takes place as described in
Programs".

18.3.1. Trigger Syntax

To create a trigger or drop a trigger, use the
The syntax for these statements is described in
Section 13.1.18,
Stored Procedures, Functions, Triggers, and
statements or the
SHOW CREATE
contents can be processed from within a stored routine, unlike the output from SHOW.
[961]
changes the same way as for statements executed outside the body of
Section 12.13, "Information
LAST_INSERT_ID()
Important
MySQL triggers are activated by SQL statements only. They are not activated
by changes in tables made by APIs that do not transmit SQL statements to the
MySQL Server; in particular, they are not activated by updates made using the
API.
NDB
"mysql_upgrade
— Check Tables for MySQL
Triggers User Forum
Triggers".
"DROP TRIGGER
Syntax".
LAST_INSERT_ID()
column of the
param_list
Functions"). The effect of a stored routine or
[961]
that is seen by following statements depends on
UPDATE
Upgrade".
of use when working with views.
Section E.1, "Restrictions on Stored
Section 18.6, "Binary Logging of Stored
CREATE TRIGGER
Section 13.1.11,
1697
mysql.proc
LAST_INSERT_ID()
LAST_INSERT_ID()
statement executes for the
Section B.5,
or
statement.
DROP TRIGGER
"CREATE TRIGGER
Syntax", and
table.
[961], the

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents