MySQL5.6不支持一个表有多个UPDATE/DELETE/INSERT触发器。 下边看一个例子: 创建三个测试表:
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) 达到了预期的结果。 |
免责声明:本站部分文章和图片均来自用户投稿和网络收集,旨在传播知识,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系我们及时修正或删除。谢谢!
始终以前瞻性的眼光聚焦站长、创业、互联网等领域,为您提供最新最全的互联网资讯,帮助站长转型升级,为互联网创业者提供更加优质的创业信息和品牌营销服务,与站长一起进步!让互联网创业者不再孤独!
扫一扫,关注站长网微信