Create trigger in MySQL

  Pi Ke        2011-04-20 15:35:30       2,512        0    

To create trigger in MySQL, the syntax is :
CREATE
    [DEFINER = { user | CURRENT_USER }]
    TRIGGER trigger_name trigger_time trigger_event
    ON tbl_name FOR EACH ROW trigger_body

One example is :

DELIMITER %%
DROP TRIGGER IF EXISTS delete_comment
CREATE TRIGGER delete_comment 
AFTER DELETE ON file_generate_info
FOR EACH ROW 
BEGIN
 DELETE FROM article_comment WHERE article_id=OLD.article_id;
END%%

The whole create trigger statement should be complete statement but not many separate commands. So we use %% as the statement delimiter. You can choose other symbols as delimiter as well.

MYSQL  TRIGGER  DILIMITER  PHPMYADMIN 

       

  RELATED


  0 COMMENT


No comment for this article.



  RANDOM FUN

RUBY, how fast can you run?

Will this RUBY car perform better than a PYTHON car if there is any? Is the boss of this car manufacturer a Ruby programmer before?   Great thanks to the image author Sina Weibo user @yutopipp for his authorization