Question

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 :)..

Was it helpful?

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.

OTHER TIPS

Delimiter problems I reckon:

DELIMITER $$

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 ;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top