# `UPDATE` Statement

__*UPDATE syntax*__

+ Syntax and example:
```
~!@// Syntax@!~
UPDATE table_name ~!@SET {col_name1}={expression1}@!~
  [,{col_name2}={expression2}, ...]
  [WHERE {condition}]
  [ORDER BY {order_by_expression}]
  [LIMIT {row_count}];

~!@// Example@!~
tidb> SELECT COUNT(*) FROM universe.planets;
+----------+
| COUNT(*) |
+----------+
|       10 |
+----------+

// Set gravity for Earth.
tidb> UPDATE universe.planets SET gravity = 9.8 ~!@WHERE name='Earth'@!~;
Query OK, ~!@1 rows affected@!~ (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

// If you omit the WHERE clause.
tidb> UPDATE universe.planets SET gravity = 9.8;
Query OK, ~!@10 rows affected@!~ (0.01 sec)
Rows matched: 10  Changed: 10  Warnings: 0
```
------------------------------------------------------------
Other than the assignment clause, the syntax for other UPDATE clauses are very similar to SELECT, essentially finding existing table rows and then modify them. If you are unfamiliar with SELECT statement, please return to the preamble course 201.2 Learn SQL from TiDB first.

A common mistake is that people do an `UPDATE` or `DELETE` without the `WHERE` statement, which leads to all rows in the table are updated or deleted.
