Today's Question:  What does your personal desk look like?        GIVE A SHOUT

Create trigger in MySQL

  Pi Ke        2011-04-20 15:35:30       2,215        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 

Share on Facebook  Share on Twitter  Share on Weibo  Share on Reddit 

  RELATED


  0 COMMENT


No comment for this article.