在mysql中创建触发器时出现错误“1064”?

时间:2011-02-15 12:52:14

标签: mysql triggers coldfusion-8

在mysql中创建触发器时遇到错误1046.我的查询是:

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

1 个答案:

答案 0 :(得分: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());