Summary: in this tutorial, you will learn how to use SQL UPDATE statement to modify existing data in a table.
SQL UPDATE syntax
The UPDATE statement changes existing data in one or more rows in a table. The following illustrates the syntax of the UPDATE statement:
UPDATE table
SET
column1 = new_value1,
column2 = new_value2,
...
WHERE
condition;Code language: SQL (Structured Query Language) (sql)To update data in a table, you need to:
- First, specify the table name that you want to change data in the
UPDATEclause. - Second, assign a new value for the column that you want to update. In case you want to update data in multiple columns, each column = value pair is separated by a comma (,).
- Third, specify which rows you want to update in the WHERE clause. The
WHEREclause is optional. If you omit theWHEREclause, all rows in the table will be updated.
The database engine issues a message specifying the number of affected rows after you execute the statement.
SQL UPDATE statement examples
Let’s take a look at some examples of using UPDATE statement with the employees table: