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

Rohit Suthar
  • 3,528
  • 1
  • 42
  • 48

2 Answers2

0

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 ;
Tom Mac
  • 9,693
  • 3
  • 25
  • 35
  • Already try but getting new error like - "#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 'DELIMITER $$" – Rohit Suthar Feb 11 '14 at 13:31
0

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.

Devart
  • 119,203
  • 23
  • 166
  • 186
  • thanks for your help but now i got new error like - "#1142 - TRIGGER command denied to user 'user'@'localhost' for table 'user'" – Rohit Suthar Feb 11 '14 at 13:33
  • 1
    CREATE TRIGGER requires this privilege - http://dev.mysql.com/doc/refman/5.6/en/create-trigger.html. You need to grant it, or create trigger from root's account. – Devart Feb 11 '14 at 14:58