MySQL allows you to update multiple columns in a single UPDATE statement. This is more efficient than running separate UPDATE statements for each column and ensures atomicity — all changes happen together.
Syntax for Multiple Columns
In the SET clause, list each column assignment separated by a comma. MySQL evaluates all assignments before applying them, so the order of column assignments in SET generally does not affect the outcome.
Updating multiple columns at once reduces round-trips to the database and keeps related data consistent. For example, when a customer moves, you might need to update both their city and postal code simultaneously.
Common Use Cases
- Updating address fields together (street, city, postal code)
- Resetting a user account (password, status, last_login)
- Adjusting product details (price, stock, updated_at)
- Batch-correcting data quality issues
Remember to test your WHERE clause first with a SELECT to confirm you are targeting the right rows before committing the UPDATE.