mysql触发器
MySQL的触发器
格式:1、触发器的定义:
CREATE TRIGGER trigger_name trigger_time trigger_event
ON tbl_name FOR EACH ROW trigger_stmt
说明:
# trigger_name:触发器名称
# trigger_time:触发时间,可取值:BEFORE或AFTER
# trigger_event:触发事件,可取值:INSERT、UPDATE或DELETE。
# tb1_name:指定在哪个表上
# trigger_stmt:触发处理SQL语句。
示例:
mysql> delimiter $$
mysql> create trigger del_stu before delete on stu for each row
-> begin
-> insert into stu_bak values(old.id,old.name,old.sex,old.age,old.addtime);
-> end;
-> $$
Query OK, 0 rows affected (0.05 sec)
mysql> delimiter ;