当运行 UPDATE ... datetime = NOW();所有更新的行都会有相同的日期/时间吗?

2022-01-17 00:00:00 datetime sql-update sql mysql

当你运行类似的东西时:

When you run something similar to:

UPDATE table SET datetime = NOW();

在具有 1 000 000 000 条记录且查询需要 10 秒才能运行的表上,所有行的时间是否完全相同(分钟和秒)还是不同的时间?换句话说,是查询开始的时间还是每行更新的时间?

on a table with 1 000 000 000 records and the query takes 10 seconds to run, will all the rows have the exact same time (minutes and seconds) or will they have different times? In other words, will the time be when the query started or when each row is updated?

我正在运行 MySQL,但我认为这适用于所有数据库.

I'm running MySQL, but I'm thinking this applies to all dbs.

推荐答案

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_now

"NOW() 返回一个常数时间,指示语句开始执行的时间.(在存储的例程或触发器中,NOW() 返回例程或触发语句开始执行的时间.)此与 SYSDATE() 的行为不同,它返回从 MySQL 5.0.13 开始执行的确切时间."

"NOW() returns a constant time that indicates the time at which the statement began to execute. (Within a stored routine or trigger, NOW() returns the time at which the routine or triggering statement began to execute.) This differs from the behavior for SYSDATE(), which returns the exact time at which it executes as of MySQL 5.0.13. "

相关文章