MySQL5.6不支持一个表有多个UPDATE/DELETE/INSERT触发器。
下边看一个例子:
创建三个测试表:
点击(此处)折叠或打开
创新互联建站专注为客户提供全方位的互联网综合服务,包含不限于成都网站制作、成都做网站、外贸营销网站建设、东区网络推广、微信小程序开发、东区网络营销、东区企业策划、东区品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联建站为所有大学生创业者提供东区建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com
-
mysql> create table t_trig_test_01 (name varchar(10));
-
Query OK, 0 rows affected (0.07 sec)
-
-
mysql> create table t_trig_test_02 (name varchar(10));
-
Query OK, 0 rows affected (0.03 sec)
-
-
mysql> create table t_trig_test_03 (name varchar(10));
-
Query OK, 0 rows affected (0.03 sec)
创建两个触发器:
-
mysql> delimiter //
-
mysql> create trigger trg_test_01
-
-> after insert on t_trig_test_01
-
-> for each row
-
-> begin
-
-> insert into t_trig_test_02 select * from t_trig_test_01;
-
-> end;
-
-> //
-
Query OK, 0 rows affected (0.06 sec)
-
-
mysql> delimiter //
-
mysql> create trigger trg_test_02
-
-> after insert on t_trig_test_01
-
-> for each row
-
-> begin
-
-> insert into t_trig_test_03 select * from t_trig_test_01;
-
-> end;
-
-> //
-
Query OK, 0 rows affected (0.11 sec)
向表t_trig_test_01插入两条测试数据:
-
mysql> insert into t_trig_test_01 values('steven');
-
Query OK, 1 row affected (0.01 sec)
-
-
mysql> insert into t_trig_test_01 values('steven');
-
Query OK, 1 row affected (0.01 sec)
查看三个表的数据:
-
mysql> select * from t_trig_test_01;
-
+--------+
-
| name |
-
+--------+
-
| steven |
-
| steven |
-
+--------+
-
2 rows in set (0.00 sec)
-
-
mysql> select * from t_trig_test_02;
-
+--------+
-
| name |
-
+--------+
-
| steven |
-
| steven |
-
| steven |
-
+--------+
-
3 rows in set (0.00 sec)
-
-
mysql> select * from t_trig_test_03;
-
+--------+
-
| name |
-
+--------+
-
| steven |
-
| steven |
-
| steven |
-
+--------+
-
3 rows in set (0.00 sec)
达到了预期的结果。
分享题目:MySQL5.7新特性之单表支持多个DML触发器
URL地址:
http://mswzjz.cn/article/picshh.html