[英]MySQL trigger query from phpMyAdmin
Im running the following query from my PhpMyadmin sql tab 我从我的PhpMyadmin sql选项卡运行以下查询
CREATE TRIGGER testTrigger
AFTER INSERT ON tbl_table1
FOR EACH ROW
BEGIN
INSERT INTO tbl_table2 (id,name) values (NEW.id,NEW.name);
END
But everytime I'm getting this error msg: 但每次我收到此错误消息:
#1064 - You have an error in your SQL syntax; #1064 - 您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 5 检查与MySQL服务器版本对应的手册,以便在第5行的''附近使用正确的语法
Im using MySQL client version: 5.1.37,PHPMyadmim Version information: 3.2.2.1deb1 我使用MySQL客户端版本:5.1.37,PHPMyadmim版本信息:3.2.2.1deb1
When you want to use
SET NEW.col_name = value
in your trigger, please note that you CANNOT use this with the AFTER the action , and must use it BEFORE the action. 如果要在触发器中使用SET NEW.col_name = value
,请注意在动作之后不能使用它,并且必须在动作之前使用它。
So probably you should try: 所以你应该尝试一下:
CREATE TRIGGER testTrigger
BEFORE INSERT ON tbl_table1
FOR EACH ROW
BEGIN
INSERT INTO tbl_table2 (id,name) values (NEW.id,NEW.name);
END
EDITED: I tried this and it's working in MySQL 编辑:我试过这个,它在MySQL中工作
DROP TRIGGER IF EXISTS testTrigger;
CREATE TRIGGER testTrigger
BEFORE INSERT ON tbl_table1
FOR EACH ROW
BEGIN
INSERT INTO tbl_table2 VALUES (NEW.id,NEW.name);
END;
Then tried INSERT INTO test1 SELECT 5,'pois';
然后尝试INSERT INTO test1 SELECT 5,'pois';
and trigger worked!! 并触发工作!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.