phpmysqlphpmyadminmysql-error-1064mysql-5.1

Trigger syntax error in phpmyadmin version 5.1


SQL Query -

CREATE TRIGGER `trigger_insert` AFTER INSERT ON `user`
    FOR EACH ROW BEGIN
        INSERT INTO `credentials` (`UserId`,`Password`,`UserType`,`Status`) 
            VALUES (NEW.UserId,NEW.Password,'2',NEW.Status);
    END;
DELIMITER ;

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 3

Need help... thanks in advance :)..


Solution

  • For your case you can use this statement -

    CREATE TRIGGER `trigger_insert` AFTER INSERT ON `user`
     FOR EACH ROW
     INSERT INTO `credentials` (`UserId`,`Password`,`UserType`,`Status`) VALUES (NEW.UserId,NEW.Password,'2',NEW.Status);
    

    What is the DELIMITER in MySQL and what it’s used for.