2013-07-25 100 views
8

我想在MySQL中創建觸發器。我運行下面的命令:如何在phpmyadmin中創建MySQL觸發器

mysql> delimiter // 
mysql> CREATE TRIGGER before_insert_money BEFORE INSERT ON money 
    -> FOR EACH ROW 
    -> BEGIN 
    -> UPDATE accounts SET balance=10.0; 
    -> END; 
    -> // 
Query OK, 0 rows affected (0.19 sec) 

但是,當我在phpMyAdmin上面的SQL運行我得到這個錯誤:

#1064 - You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to 
use near '' at line 4 

這裏有什麼錯?我如何創建觸發器?

回答

9

這是因爲您沒有像通過CLI那樣臨時更改分隔符而造成的。嘗試之一:

CREATE TRIGGER before_insert_money BEFORE INSERT ON money 
FOR EACH ROW UPDATE accounts SET balance=10.0; 

delimiter // 
CREATE TRIGGER before_insert_money BEFORE INSERT ON money 
FOR EACH 
ROW 
BEGIN 
    UPDATE accounts SET balance=10.0; 
END; 
// 
delimiter ; 

見:This questionthis question