开发者

Update mysql table on Insert command

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 n开发者_Python百科ot 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


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 ;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜