this is the query that i am using
这是我正在使用的查询
create trigger trig1 after insert on participant for each row
begin
insert into team(sap) select sap from participant order by ID desc limit 1,1
end;
it is supposed to copy the sap field from the participant table into the sap field of the team table after a new row is inserted into the participant table the engine shows me an unexpected end of input error at the end of "end"
当一个新的行被插入到参与者表中时,它应该从参与者表中将sap字段复制到团队表的sap字段中。
i've tried numerous methods to rework the query but i keep getting the same error what am i doing wrong?
我尝试了很多方法来重做查询,但是我总是得到相同的错误我做错了什么?
thanks
谢谢
1 个解决方案
#1
3
You are using trigger than no need to run a query on same table to get latest sap value, you can directly get that value using new.sap.
您正在使用触发器,不需要在同一个表上运行查询来获取最新的sap值,您可以使用new.sap直接获取该值。
Problem in your query, In your query you haven't put semicolon(;) after INSERT..SELECT query and END keyword.
查询中的问题,在查询中没有将分号(;)插入。选择query和END关键字。
This will work for you:
这对你有用:
DELIMITER $$
DROP TRIGGER /*!50032 IF EXISTS */ `trig1`$$
CREATE
TRIGGER `trig1` AFTER INSERT ON `participant`
FOR EACH ROW BEGIN
INSERT INTO team(sap)
VALUES(new.sap);
END;
$$
DELIMITER ;
#1
3
You are using trigger than no need to run a query on same table to get latest sap value, you can directly get that value using new.sap.
您正在使用触发器,不需要在同一个表上运行查询来获取最新的sap值,您可以使用new.sap直接获取该值。
Problem in your query, In your query you haven't put semicolon(;) after INSERT..SELECT query and END keyword.
查询中的问题,在查询中没有将分号(;)插入。选择query和END关键字。
This will work for you:
这对你有用:
DELIMITER $$
DROP TRIGGER /*!50032 IF EXISTS */ `trig1`$$
CREATE
TRIGGER `trig1` AFTER INSERT ON `participant`
FOR EACH ROW BEGIN
INSERT INTO team(sap)
VALUES(new.sap);
END;
$$
DELIMITER ;