一、创建触发器

1.创建有一条执行语句的触发器

CREATE TRIGGER trigger_name

  BEFORE|AFTER trigger_EVENT(INSERT|DELETE|UPDATE)

    ON TABLE_NAME FOR EACH ROW trigger_STMT;

2.创建包含多条执行语句的触发器

DELIMITER $$

CREATE TRIGGER trigger_name

  BEFORE|AFTER trigger_EVENT(INSERT|DELETE|UPDATE)

    ON TABLE_NAME FOR EACH ROW

      BEGIN

      trigger_STMT1;

      trigger_STMT2;

      。。。

      END

DELIMITER ;

DELIMITER $$:将$$设置为结束符号

二、查看触发器

1.SHOW TRIGGERS \G

2.通过查看系统表triggers实现查看触发器

USE information_schema;

SELECT * FROM triggers \G或者SELECT * FROM triggers WHERE trigger_name='...';

三、删除触发器

DROP TRIGGER trigger_name;

05-22 19:14