触发器已成功创建,但它无法正常工作

时间:2014-03-09 13:10:09

标签: mysql triggers

我已创建此触发器,一旦将记录插入另一个表

,就会将记录插入另一个表中
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 ;

此触发器已成功创建,但未在messageout表中插入任何消息。原因是什么?。

1 个答案:

答案 0 :(得分:1)

此触发器错误,包含两个错误:

试试这段代码:

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 

工作演示的链接:http://sqlfiddle.com/#!2/bdbff/1