- 论坛徽章:
- 0
|
触发器
CREATE TRIGGER Syntax
CREATE TRIGGER trigger_name trigger_time trigger_event
ON tbl_name FOR EACH ROW trigger_stmt
A trigger is a named database object that is associated with a table,
and that activates when a particular event occurs for the table.
触发器是一个被指定关联到一个表的数据对象,当对个表的特别事件出现时,它被激
活
The trigger becomes associated with the table named tbl_name. tbl_name
must refer to a permanent table. You cannot associate a trigger with a
TEMPORARY table or a view.
触发器关联的表叫 tbl_name ,tal_name必须是一个永久表.你不能用一个内在表或
者视图关联到触发器.
trigger_time is the trigger action time. It can be BEFORE or AFTER to
indicate that the trigger activates before or after the statement that
activated it.
trigger_time 是触发器执行时间.它可以是BEFORE或者AFTER,以便指出触发器在声
明它之前或之后被激活.
trigger_event indicates the kind of statement that activates the
trigger. It can be INSERT, UPDATE, or DELETE. For example, a BEFORE
trigger for INSERT statements could be used to check the values to be
inserted into new rows.
trigger_event指出几种激活触发器的声明.它可以是INSERT,UPDATE,或者DELETE.
例如一个BEFORE的INSERT事件的触发器能被用于检查插入多少新行的值.
There cannot be two triggers for a given table that have the same
trigger action time and event. For example, you cannot have two BEFORE
UPDATE triggers for a table. But you can have a BEFORE UPDATE and a
BEFORE INSERT trigger, or a BEFORE UPDATE and an AFTER UPDATE trigger.
对于同一个表,我们不能创建两个触发器,它们有相同的执行时间和事件.例如对于
一个表,你不能有两BEFORE UPDATE触发器.但你能有一个BEFORE UPDATE 触发器和
一个BEFORE INSERT触发器,或者一个BEFORE UPDATE和AFTER UPDATE触发器.
trigger_stmt is the statement to execute when the trigger activates. If
you want to execute multiple statements, use the BEGIN ... END compound
statement construct. This also enables you to use the same statements
that are allowable within stored routines. See section BEGIN ... END
Compound Statement.
trigger_stmt 是一个当触发器激活时,去执行的语句.使用BEGIN ... END复合语句
结构.在存储程序内部使用同一个语句,也是有效的.看BEGIN ... END 复合语句 部
分.
Note: Currently, triggers have the same limitation as stored functions
that they may not contain direct references to tables by name. This
limitation will be lifted as soon as possible.
注意:当前,触发器有与存储函数相同的局限,它不能能过名字直接引用.这个限制会
尽快提到日程上来.
However, in the triggered statement, you can refer to columns in the
table associated with the trigger by using the names OLD and NEW.
OLD.col_name refers to a column of a an existing row before it is
updated or deleted. NEW.col_name refers to the column of a new row to be
inserted or an existing row after it is updated.
尽管如此,在触发器的语句中,通过使用OLD和NEW,你能引用到一个关联到触发器表
的列.OLD.col_name可以引有到一个在被更新或者删除之前存在的列.NEW.col_name
引用新列或者被更新列.
Use of SET NEW.col_name = value requires the UPDATE privilege on the
column. Use of SET value = NEW.col_name requires the SELECT privilege on
the column.
使用SET NEW.col_name=value 请求一个在列上UPDATE的特权.使用set
value=NEW.col_name命令请求一个在列上SELECT的特权.
The CREATE TRIGGER statement requires the SUPER privilege. It was added
in MySQL 5.0.2.
CREATE TRIGGER语句中请求一个SUPER特权.它将在MySQL 5.0.2上被添加.
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/14250/showart_237227.html |
|