Binoy Dalal
Binoy Dalal

Reputation: 896

MySQL Trigger syntax error unexpected end of input

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"

i've tried numerous methods to rework the query but i keep getting the same error what am i doing wrong?

thanks

Upvotes: 4

Views: 6978

Answers (1)

Saharsh Shah
Saharsh Shah

Reputation: 29051

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.

Problem in your query, In your query you haven't put semicolon(;) after INSERT..SELECT query and END keyword.

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 ;

Upvotes: 4

Related Questions