When running UPDATE ... datetime = NOW(); will all rows updated have the same date/time?

Darryl Hein picture Darryl Hein · Oct 12, 2008 · Viewed 101.4k times · Source

When you run something similar to:

UPDATE table SET datetime = NOW();

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?

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

Answer

micahwittman picture micahwittman · Oct 12, 2008

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

"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. "