mysql
sql
update statement
now function
database tutorial

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.

Practice system design

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:

sql
1UPDATE orders
2SET created_at = NOW(),
3    processed_at = NOW()
4WHERE id = 42;

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:

sql
1CREATE TABLE audit_demo (
2    id INT PRIMARY KEY,
3    started_at DATETIME,
4    finished_at DATETIME
5);
6
7INSERT INTO audit_demo (id, started_at, finished_at)
8VALUES (1, NULL, NULL);

Now run:

sql
1UPDATE audit_demo
2SET started_at = NOW(),
3    finished_at = NOW()
4WHERE id = 1;
5
6SELECT started_at, finished_at
7FROM audit_demo
8WHERE id = 1;

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:

sql
1UPDATE audit_demo
2SET started_at = NOW(6),
3    finished_at = NOW(6)
4WHERE id = 1;

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.

sql
1SET @ts = NOW();
2
3UPDATE audit_demo
4SET started_at = @ts,
5    finished_at = @ts
6WHERE id = 1;

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:

sql
UPDATE audit_demo
SET started_at = NOW(),
    finished_at = NOW();

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:

sql
SELECT @@session.time_zone;

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:

sql
1UPDATE jobs
2SET locked_at = NOW(),
3    last_seen_at = NOW(),
4    status = 'running'
5WHERE id = 1001;

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 one UPDATE statement.
  • 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() or CURRENT_TIMESTAMP over SYSDATE() when matching values matter.
  • Keep the session time zone in mind so consistent timestamps are also semantically correct.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.