MySQL CREATE TRIGGER:
CREATE TRIGGER `validate_email_insert` BEFORE INSERT ON `testusers`
FOR EACH ROW
BEGIN
IF NEW.`email` NOT LIKE ‘%_@%_.__%’ THEN
SIGNAL SQLSTATE VALUE ‘45000’
SET MESSAGE_TEXT = ‘[table:person] – NEW.`email` column is not valid’;
END IF;
END;
Error
SQL query:
CREATE TRIGGER `validate_email_insert` BEFORE INSERT ON `testusers`
FOR EACH
ROW
BEGIN
IF NEW.`email` NOT LIKE ‘%_@%_.__%’
THEN
SIGNAL SQLSTATE VALUE ‘45000’
SET MESSAGE_TEXT = ‘[table:person] – NEW.`email` column is not valid’;
#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 6
FIX:
You need to add the DELIMITER value in order to fix the above errors:
delimiter //
CREATE TRIGGER `validate_email_insert` BEFORE INSERT ON `testusers`
FOR EACH ROW
BEGIN
IF NEW.`email` NOT LIKE ‘%_@%_.__%’ THEN
SIGNAL SQLSTATE VALUE ‘45000’
SET MESSAGE_TEXT = ‘[table:person] – NEW.`email` column is not valid’;
END IF;
END;//
<