mysql用相同的now()更新多个列 [英] mysql update multiple columns with same now()

查看:121
本文介绍了mysql用相同的now()更新多个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更新2个datetime列,并且需要使用mysql 4.1.20版本使它们完全相同.我正在使用此查询:

I need to update 2 datetime columns, and I need them to be exactly the same, using mysql version 4.1.20. I'm using this query:

mysql> update table set last_update=now(), last_monitor=now() where id=1;

这是安全的,或者由于对now()的2次可见调用,所以有可能在不同的时间更新这些列?
我不认为可以用不同的值来更新它(我认为mysql内部每行一次调用now()或类似的命令),但是我不是专家,您怎么看?

It is safe or there is a chance that the columns are update with different time, because of the 2 visible calls to now()?
I don't think that it can be update with different values (I think internally mysql calls now() just once per row or something similar), but I'm not an expert, what do you think?

更新: 第二个问题是在此处提取的.

Update: Second question was extracted here.

推荐答案

找到了解决方案:

mysql> UPDATE table SET last_update=now(), last_monitor=last_update WHERE id=1;

我在MySQL Docs中找到经过几次测试后,它可以正常工作:

I found this in MySQL Docs and after a few tests it works:

以下语句将col2设置为当前(更新)的col1值,而不是原始的col1值.结果是col1和col2 具有相同的值.此行为不同于标准SQL.

the following statement sets col2 to the current (updated) col1 value, not the original col1 value. The result is that col1 and col2 have the same value. This behavior differs from standard SQL.

更新t1设置col1 = col1 + 1,col2 = col1;

这篇关于mysql用相同的now()更新多个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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