MySQL5.6不支持一個(gè)表有多個(gè)UPDATE/DELETE/INSERT觸發(fā)器。 下邊看一個(gè)例子: 創(chuàng)建三個(gè)測試表:
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) 創(chuàng)建兩個(gè)觸發(fā)器: 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插入兩條測試數(shù)據(jù):
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) 查看三個(gè)表的數(shù)據(jù):
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) 達(dá)到了預(yù)期的結(jié)果。 |
免責(zé)聲明:本站部分文章和圖片均來自用戶投稿和網(wǎng)絡(luò)收集,旨在傳播知識(shí),文章和圖片版權(quán)歸原作者及原出處所有,僅供學(xué)習(xí)與參考,請勿用于商業(yè)用途,如果損害了您的權(quán)利,請聯(lián)系我們及時(shí)修正或刪除。謝謝!
始終以前瞻性的眼光聚焦站長、創(chuàng)業(yè)、互聯(lián)網(wǎng)等領(lǐng)域,為您提供最新最全的互聯(lián)網(wǎng)資訊,幫助站長轉(zhuǎn)型升級,為互聯(lián)網(wǎng)創(chuàng)業(yè)者提供更加優(yōu)質(zhì)的創(chuàng)業(yè)信息和品牌營銷服務(wù),與站長一起進(jìn)步!讓互聯(lián)網(wǎng)創(chuàng)業(yè)者不再孤獨(dú)!
掃一掃,關(guān)注站長網(wǎng)微信