2011-02-15 76 views
0

而在MySQL的IM創造觸發收到錯誤1046我的查詢是:錯誤「1064」在觸發器創建在MySQL?

CREATE TABLE test.Employee(
       id   int, 
       first_name VARCHAR(30), 
       last_name  VARCHAR(15), 
       start_date DATE, 
       end_date  DATE, 
       city   VARCHAR(10), 
       description VARCHAR(15) 
     ); 


CREATE TABLE test.Employee_log(
       id int, 
       first_name varchar(50), 
       last_name varchar(50), 
       start_date date, 
       end_date date, 
       city varchar(50), 
       description varchar(50), 
       Lasinserted Time 
     ); 

當我執行它下面是給錯誤行:

Error Code : 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 'END$$ 
delimiter' at line 1 
(16 ms taken) 


delimiter $$ 
CREATE TRIGGER test.Employee_Trigger 
    AFTER insert ON test.employee 
    FOR EACH ROW 
    BEGIN 
    insert into test.employee_log values(new.id,new.first_name, 
    new.last_name,new.start_date,new.end_date, 
    new.city,new.description,curtime()); 
    END$$ 
delimiter ; 


如果某些人能請幫助它將非常感激。


謝謝
Yugal

回答

5

觸發不是常規的,也沒有存儲過程,
所以不需要爲BEGIN...END,再加上表名是區分大小寫的

CREATE TRIGGER Employee_Trigger 
AFTER insert ON Employee 
FOR EACH ROW 
INSERT INTO test.Employee_log values(new.id,new.first_name, 
    new.last_name,new.start_date,new.end_date, 
    new.city,new.description,curtime()); 
+0

瞧它的工作原理。非常感謝 – Yugal 2011-02-15 14:24:09