MySQL5.7新特性之单表支持多个DML触发器
作者:互联网
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)
达到了预期的结果。
标签:01,MySQL5.7,steven,DML,sec,单表,mysql,test,trig 来源: https://blog.51cto.com/u_12592884/2693905