我正在尝试在MySql 5.1.41中执行触发器语句,但是我收到的错误超出了我的理解范围。任何帮助将不胜感激。
以下是触发代码:
create TRIGGER populate_modality_trigger AFTER INSERT on series
FOR EACH ROW BEGIN
DECLARE x int;
select count(*) into x from lu_modality_alias l WHERE l.modality=NEW.modality;
IF (x =0 OR x is NULL) THEN
INSERT INTO lu_modality_alias
set modality = NEW.modality,
modality_alias = NEW.modality
;
END if;
end;
当我运行上面的代码时,我收到以下错误:
MySQL说:文档#1064 - 你的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第3行的''附近使用正确的语法
有趣的是,当我从Naviacat查询编辑器执行相同的代码时,它会成功运行并创建触发器。 但是phpMyAdmin sql也失败了。
答案 0 :(得分:2)
您需要更改分隔符,以便MySql解析器不会在第一个分号结束时解析CREATE语句
delimiter //
create TRIGGER populate_modality_trigger AFTER INSERT on series
FOR EACH ROW BEGIN
DECLARE x int;
select count(*) into x from lu_modality_alias l WHERE l.modality=NEW.modality;
IF (x =0 OR x is NULL) THEN
INSERT INTO lu_modality_alias
set modality = NEW.modality,
modality_alias = NEW.modality
;
END if;
end //
delimiter ;