简体   繁体   English

如何在MySQL中同时在两个表中存储相同的时间戳

[英]How to store same time stamp in two tables at same time in mysql

I am a newbie and using mysql . 我是新手,正在使用mysql I have two table products and customers and there is a column DATE in both the table which stores the current timestamp whenever the record is modified . 我有两个表产品客户 ,两个表中都有一个DATE列,每当记录被修改时,它都会存储当前时间戳 Now I have to update a row in both the tables but I want the CURRENT timestamp to be stored same in both the tables. 现在,我必须在两个表中都更新一行,但我想将CURRENT时间戳记存储在两个表中。 I have found that UPDATE does not take multiple table names at the same time. 我发现UPDATE不能同时使用多个表名。 I know that this must be simple but I have no idea how to do it. 我知道这一定很简单,但是我不知道该怎么做。 May be I am unable to identify the logic to do it. 可能是我无法确定执行此操作的逻辑。 Thanks for helping me out and sorry for the lame question :-p 感谢您的帮助,也很抱歉提出for脚的问题:-p

Use a procedure 使用程序

delimiter |
CREATE PROCEDURE updatewithtime(IN inputid int)
BEGIN      
    set @timestamp := now();
    update products set date = @imestamp where id = inputid;
    update customers set date = @imestamp where id = inputid;
END
|
delimiter ;

You can call that like this 你可以这样叫

call updatewithtime(123);
UPDATE TableaA a INNER JOIN TableB b ON (a.id= b.id)
SET
 //set values
WHERE a.id= 100  AND b.id= 100

Note : You can not use limit . 注意:您不能使用limit

Still i will prefer the way given by juergen d (Stored procedure) 我仍然会喜欢juergen d(存储过程)给出的方式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM