2014-10-05 118 views
0

我做了一個觸發器:觸發更新或刪除mysql的

delimiter | 
CREATE TRIGGER update_table2 after UPDATE ON table1 
FOR EACH ROW 
BEGIN 
    //here goes an update action 
END | 
delimiter ; 

現在我想,這觸發雲也:after DELETE ON table1

我想是這樣的:

delimiter | 
CREATE TRIGGER update_table2 after UPDATE or DELETE ON table1 
FOR EACH ROW 
BEGIN 
    //here goes an update action 
END | 
delimiter ; 

但這不是加工。我知道我可以創建一個特定的觸發器,但爲了易讀,我想用這種方式。 希望mySql支持這個。

回答

0

您必須創建兩個觸發器(在OR條款是T-SQL等)

但爲了避免日後的維護問題,你可以從兩個觸發器調用的存儲過程:

delimiter | 
CREATE TRIGGER update_table2 after UPDATE ON table1 
FOR EACH ROW 
BEGIN 
    //here goes an update action 
    call sp_trigger_table1([params]); 
END | 
delimiter ; 


delimiter | 
CREATE TRIGGER update_table2 after DELETE ON table1 
FOR EACH ROW 
BEGIN 
    //here goes an DELETE action 
    call sp_trigger_table1([params]); 
END | 
delimiter ;