例:create trigger trig_book after insert on t_book for each row update t_bookType SET bookNum=bookNum+1 where new.bookTypeId=t_booktype.id; //new是过度变量,刚刚操作过的数据
执行多条语句:
DELIMITER |CREATE TRIGGER trig_book2 AFTER DELETE ON t_book FOR EACH ROW BEGIN UPDATE t_bookType SET bookNum=bookNum-1 WHERE old.bookTypeId=t_booktype.id; INSERT INTO t_log VALUES(NULL,NOW(),'在book表里删除了一条数据'); DELETE FROM t_test WHERE old.bookTypeId=t_test.id; END |DELIMITER ;
查看触发器:show triggers +触发器名; 在trigger表中查看触发器
删除触发器:drop triggers +触发器名;