user1908583
user1908583

Reputation: 27

Error 1064 during trigger creation

I want to create a trigger on one of the tables, it's very simple, just to set one value - but I always get error 1064

CREATE TRIGGER `trigger_TEST` BEFORE INSERT ON `TEST_table` 
FOR EACH ROW 
BEGIN
        IF NEW.as_src = 13335 THEN
            SET NEW.peer_as_src = 13335;
        END IF
END

And get this error:

Error SQL (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 '' at line 5

Any idea why ?

Upvotes: 1

Views: 204

Answers (1)

juergen d
juergen d

Reputation: 204766

You need to change the default delimiter

delimiter |
CREATE TRIGGER `trigger_TEST` BEFORE INSERT ON `TEST_table` 
FOR EACH ROW 
BEGIN
        IF NEW.as_src = 13335 THEN
            SET NEW.peer_as_src = 13335;
        END IF;
END
|
delimiter ;

Otherwise the statement will end at the first ; which would make the trigger definition incomplete.

Upvotes: 3

Related Questions