MySQL trigger results in error #1064

I tried writing this small trigger in MySQL,

CREATE TRIGGER `leg` BEFORE INSERT ON `bckoff` 
FOR EACH ROW BEGIN
 INSERT INTO `bckoff` SET `step`=1;
END;

after which I get this error.. I'm a newbie to MySQL.. so please help me out here..

#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 3 

Upvotes: 1

Views: 2617

Answers (1)

zerkms
zerkms

Reputation: 255105

Even after you fix this error - you'll get another one: you cannot modify the table that your trigger was created at.

Btw, this is how you should create this trigger:

delimiter |

CREATE TRIGGER `leg` BEFORE INSERT ON `bckoff` 
FOR EACH ROW BEGIN
 INSERT INTO `bckoff` SET `step`=1;
END;
|

delimiter ;

Upvotes: 2

Related Questions