Update mysql table on Insert command

人盡茶涼 提交于 2020-03-16 07:06:50

问题


I have a situation in which I want to update a the second table when a row of data is inserted in the first table. To achieve this I am using mysql triggers and below is the query I am using, but its not working for me.

DELIMITER $$ 
CREATE TRIGGER after_insert;

AFTER INSERT ON table_first

  FOR EACH ROW BEGIN 

    INSERT INTO table_second 
      (value1, rvalue2, value3)
    VALUES 
      ('123456', '654321', 'hello trigger')

  END

DELIMITER ;

Both the tables exists in the same database. Thanks


回答1:


Some small syntax problems ... here :

DELIMITER $$ 
CREATE TRIGGER after_insert  -- remove ;
AFTER INSERT ON table_first
  FOR EACH ROW BEGIN 
    INSERT INTO table_second 
      (value1, rvalue2, value3)
    VALUES 
      ('123456', '654321', 'hello trigger');    -- add ;
  END
$$ -- add $$

DELIMITER ;


来源:https://stackoverflow.com/questions/5946137/update-mysql-table-on-insert-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!