mysql update multiple columns with same now
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Yes. In MySQL, you can update multiple columns with NOW() in a single UPDATE statement, and every reference to NOW() within that statement uses the same timestamp value. That means you do not need a variable just to keep the two columns synchronized inside one query.
Basic UPDATE Syntax
If two columns should receive the same current timestamp, write them both in the same SET clause:
Because both assignments happen in the same statement, created_at and processed_at will receive the same value.
That is the key point. In MySQL, NOW() is evaluated once per query at the start of execution, not separately for each column reference.
A Small Demonstration
Suppose you have a table like this:
Now run:
The two selected values will match exactly, including fractional seconds if the columns and function call use that precision.
Using Fractional Seconds
If your columns support fractional seconds precision, you can request it explicitly:
NOW(6) includes microseconds. Again, both references in the same statement will still match.
This is useful for audit columns or event timing where sub-second precision matters.
When a Variable Can Still Help
Although you do not need a variable for correctness inside one statement, some developers still prefer one for readability, especially in larger scripts.
This is fine, but it is more verbose and spans multiple statements. For a simple update, repeated NOW() calls inside one UPDATE are already consistent.
NOW() Versus SYSDATE()
This is where confusion often starts. NOW() behaves like a statement timestamp. SYSDATE() behaves more like "current wall-clock time at the moment the function executes."
So this is usually what you want:
If you use SYSDATE() repeatedly, the values can differ because the function is not tied to a single statement-start time in the same way.
That makes NOW() or CURRENT_TIMESTAMP the safer choice when you want matching values across columns.
Session Time Zone Still Matters
NOW() returns the current timestamp in the session time zone. So even though the two columns will match each other, the actual displayed value depends on the connection's time-zone settings.
You can inspect the session time zone with:
If your application expects UTC storage, make sure the connection or server is configured accordingly, or convert timestamps explicitly as part of your design.
A More Realistic Example
Here is a common pattern in workflow tables:
This is compact, readable, and consistent. The same query can be used to stamp several lifecycle columns without worrying that one column is a few microseconds later than another.
Common Pitfalls
One common mistake is assuming repeated NOW() calls in one query could drift slightly. In MySQL, they do not. They are evaluated once per query.
Another issue is mixing NOW() with SYSDATE() and expecting identical behavior. They are not the same function and should not be treated as interchangeable when exact consistency matters.
Developers also sometimes forget about the session time zone. Matching timestamps can still be "wrong" for the business case if the session zone is not the one you expected.
Finally, be careful with the WHERE clause. The timestamp logic may be correct while the update still affects far more rows than intended.
Summary
- You can update multiple columns with
NOW()in oneUPDATEstatement. - In MySQL, multiple references to
NOW()within a single query return the same timestamp. - Use
NOW(6)if you need fractional seconds precision. - Prefer
NOW()orCURRENT_TIMESTAMPoverSYSDATE()when matching values matter. - Keep the session time zone in mind so consistent timestamps are also semantically correct.
Related reading
- MySQL, update multiple tables with one query
- MySQL user DB does not have password columns - Installing MySQL on OSX
- MySQL variable vs. variable. What's the difference?
- MySQL vs MongoDB 1000 reads
- MySQL vs MySQLi when using PHP
- MySQL vs PostgreSQL for Web Applications
- MySQL What is a page?
- MySQL What's the difference between float and double?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.