Vidyadhar Mandke
Vidyadhar Mandke

Reputation: 588

Something wrong in creating mysql trigger

Hi i'm trying to create below trigger

CREATE TRIGGER TRIGBEFORE INSERT ON employee FOR EACH ROW BEGIN UPDATE employee SET userId = userId +1 WHERE userId >1; END

it is giving me below mysql error, please suggest what is wrong in it.

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

Upvotes: 0

Views: 94

Answers (2)

juergen d
juergen d

Reputation: 204746

you forgot to set the delimiter and misspelled a word:

delimiter |
CREATE TRIGGER TRIG BEFORE INSERT ON employee 
FOR EACH ROW BEGIN 
    UPDATE employee SET userId = userId +1 WHERE userId >1; 
END;
|
delimiter ;

If you don't set another delimiter than ; the statement will end at the first ; and your trigger definition will be incomplete. You need to tell MySQL that the stamentment should end at the delimiter you defined. After that you can set the delimiter back with delimiter ;

Upvotes: 2

Omesh
Omesh

Reputation: 29061

I think you have a typo mistake TRIGBEFORE: manual here

CREATE TRIGGER trigger_name BEFORE INSERT ON ...

Upvotes: 0

Related Questions