2012-11-21 67 views
1

嗨我堅持使這個觸發器插入我的日誌表的值的語法。使用SQL選項卡里面phpmyadmin的錯誤執行SQL語句創建觸發器將UNIX_TIMESTAMP()插入到日誌表中

`#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 8 ` 

這裏之前似乎是在創建觸發器

CREATE TRIGGER after_insert_list 
AFTER INSERT ON list FOR EACH ROW 
BEGIN 
    INSERT INTO log (user_id, action, date_log) 
    VALUES (
     NEW.user_id, 
     NEW.action, 
     UNIX_TIMESTAMP() 
    ); 
END 
+2

難道你一定要先改變分隔符? –

+0

@傑克你能否介紹一下嗎?我有點困惑。順便說一下,我正在關注net tuts上的這個教程http://net.tutsplus.com/tutorials/databases/introduction-to-mysql-triggers/ – ianace

+0

你可以在[manual](http: //dev.mysql.com/doc/refman/5.0/en/trigger-syntax.html) –

回答

0

創建您的觸發條件如下我的SQL語句:

delimiter | 
CREATE TRIGGER testref 
BEFORE INSERT ON test1FOR EACH ROW BEGIN 
INSERT INTO test2 SET a2 = NEW.a1; 
DELETE FROM test3 WHERE a3 = NEW.a1; 
UPDATE test4 SET b4 = b4 + 1 WHERE a4 = NEW.a1; 
END; 
| 
delimiter ; 
+0

我剛剛找到了一個更簡單的方法,我的phpmyadmin觸發器選項卡.. – ianace