FIX: MySQL Error: #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

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;

image 

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’;

MySQL said: Documentation

#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

 

image

 

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;//

 

<

p>image

Leave a Reply

Your email address will not be published. Required fields are marked *