Reputation:
I have created this trigger that inserts a record into another table once a record has been inserted in another table
DELIMITER $$
CREATE TRIGGER logan AFTER INSERT ON messagein
FOR EACH ROW
BEGIN
DECLARE le_number INT;
SET le_number = (select messagefrom from messagein where id=NEW.id);
insert into messageout (MessageTo,MessageText) VALUES(le_number,"Thank you for contacting our company.Our sales representatives shall be in touch with you soon.");
END $$
DELIMITER ;
This trigger is created successfully but no message is inserted into the messageout
table.What is the reason for this?.
Upvotes: 0
Views: 92
Reputation: 36127
This trigger is wrong, it contains two errors:
Try this code:
CREATE TRIGGER logan AFTER INSERT ON messagein
FOR EACH ROW
BEGIN
insert into messageout (MessageTo,MessageText)
VALUES(NEW.messagefrom,'Thank you for contacting our company.Our sales representatives shall be in touch with you soon.');
END
A link to working demo: http://sqlfiddle.com/#!2/bdbff/1
Upvotes: 1