Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The single table of MySQL5.7 's new features supports multiple DML triggers.

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

MySQL5.6 does not support multiple UPDATE/DELETE/INSERT triggers for a table.

Let's look at an example:

Create three test tables:

Click (here) to collapse or open

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) create two triggers:

Click (here) to collapse or open

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) inserts two pieces of test data into the table t_trig_test_01:

Click (here) to collapse or open

Mysql > insert into t_trig_test_01 values ('steven')

Query OK, 1 row affected (0.01sec)

Mysql > insert into t_trig_test_01 values ('steven')

Query OK, 1 row affected (0.01 sec) to view the data of three tables:

Click (here) to collapse or open

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) achieved the expected results.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report