1、觸發(fā)器的創(chuàng)建
1.1創(chuàng)建有一條執(zhí)行語句的觸發(fā)器
語法:
create trigger trigger_name before|after trigger_enent on table_name for each row trigger_stmt
實(shí)例:
mysql> create trigger trigger_test before insert on t1 for each row
-> insert t1_log values(USER(),'insert record into t1',now());
2、多條執(zhí)行語句的觸發(fā)語句
語法:
mysql> delimiter $$//指定結(jié)束符,默認(rèn)的式分好,多條語句會沖突,所以要重新定義下,使用完,可以重新制定為分號
mysql> create trigger trigger_test after insert on t1 for each row
-> begin
-> insert into t1_log values(USER(),'after into t1',now());
-> insert into t1_log values('wangsi','after into t1',now());
-> end
-> $$
3、觸發(fā)器的查看:
方法1:
語法:
show triggers \G
方法2:
mysql> user information_schema;
mysql> select * from triggers where trigger_name='trigger_test'\G;
4、觸發(fā)器的修改:
觸發(fā)器不能修改,只能將原來的刪除,然后創(chuàng)建新的觸發(fā)器
5、觸發(fā)器的刪除:
drop trigger trigger_name;
聯(lián)系客服