在插入命令上更新mysql表 [英] Update mysql table on Insert command

查看:87
本文介绍了在插入命令上更新mysql表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一种情况下,当我在第一张表中插入一行数据时,我想更新第二张表.为此,我正在使用mysql触发器,下面是我正在使用的查询,但不适用于我.

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

推荐答案

一些小的语法问题...在这里:

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 ;

这篇关于在插入命令上更新mysql表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆