error “1064” in trigger creation in mysql?

六眼飞鱼酱① 提交于 2019-12-31 07:29:24

问题


while creating trigger in mysql i m getting error 1046. my query is:

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
          );

when i am executing below lines it is giving error:

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 ;


if some one could please help it would be greately appreciated.


Thanks
Yugal


回答1:


trigger are not routine nor stored procedure,
so there is not need for BEGIN...END, plus the table name is case sensitive

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());


来源:https://stackoverflow.com/questions/5003869/error-1064-in-trigger-creation-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!