Trigger keeps creating error
You are viewing an old version of this question. View
the current version here.
I am not understanding why I keep getting this error. Can anyone explain? I am entering it through HeidiSQL:
################################ # CHECK Triggers for WM_CLIENT ################################ CREATE TRIGGER trig_client_gndr BEFORE INSERT ON WM_CLIENT FOR EACH ROW BEGIN IF UPPER(NEW.ClGender) NOT IN ('M','F') THEN SET NEW.ClGender ='U'; END IF; END;
I get the error: SQL Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near " at line 10.
Line 10 is SET NEW ClGender = 'U';
Answer
Since your trigger creation contains semicolons, you need to change the statement delimiter. Something like
DELIMITER | CREATE TRIGGER trig_client_gndr BEFORE INSERT ON WM_CLIENT FOR EACH ROW BEGIN IF UPPER(NEW.ClGender) NOT IN ('M','F') THEN SET NEW.ClGender ='U'; END IF; END | DELIMITER ;
Comments
Comments loading...
Content reproduced on this site is the property of its respective owners,
and this content is not reviewed in advance by MariaDB. The views, information and opinions
expressed by this content do not necessarily represent those of MariaDB or any other party.