MySQL Tutorial/Trigger/Introduction — различия между версиями

Материал из SQL эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 09:49, 26 мая 2010

Activation Time

Use BEFORE to perform an action prior to the change being made in the table.

Use AFTER to perform an action after the changes are made in the table.

When you choose AFTER, you cannot change the values of the incoming query.

13. 1. Introduction 13. 1. 1. <A href="/Tutorial/MySQL/0260__Trigger/TheCREATETRIGGERStatement.htm">The CREATE TRIGGER Statement</a> 13. 1. 2. Activation Time 13. 1. 3. <A href="/Tutorial/MySQL/0260__Trigger/OLDandNEWKeywords.htm">OLD and NEW Keywords</a>

OLD and NEW Keywords

Two keywords are unique to SQL statements used in defining triggers: OLD and NEW.

These keywords allow you to refer to the data before and after the activating event takes place.

For example, OLD.<fieldname>, NEW.<fieldname>.

13. 1. Introduction 13. 1. 1. <A href="/Tutorial/MySQL/0260__Trigger/TheCREATETRIGGERStatement.htm">The CREATE TRIGGER Statement</a> 13. 1. 2. <A href="/Tutorial/MySQL/0260__Trigger/ActivationTime.htm">Activation Time</a> 13. 1. 3. OLD and NEW Keywords

The CREATE TRIGGER Statement

The CREATE TRIGGER statement is used to define a trigger.

The CREATE TRIGGER statement associates it with changes occurring in a table.

It has the following syntax:



CREATE TRIGGER <name> <time> <event>
ON <table>
FOR EACH ROW
<body statements>


With the time and event, you must choose from an enumerated set of options:

CREATE TRIGGER <name> [BEFORE | AFTER] [INSERT | UPDATE | DELETE]