UPDATE
statementsupportedQueries & DMLUpdates specified rows in the target table with new values.
Syntax
supportedpartialnot supportednot scored
UPDATE <target_table>
SET <col_name> = <value> [ , <col_name> = <value> , ... ]
[ FROM <additional_tables> ]
[ WHERE <condition> ]
Parameters
| Name | Required | Description |
|---|---|---|
target_table | required | Specifies the table to update. |
col_name | required | Specifies the name of a column in target_table. Do not include the table name. For example, UPDATE t1 SET t1.col = 1 is invalid. |
value | required | Specifies the new value to set in col_name. |
FROM additional_tables | optional | Specifies one or more tables to use for selecting rows to update or for setting new values. Note that repeating the target table results in a self-join. |
WHERE condition | optional | Expression that specifies the rows in the target table to update. Default: No value (all rows of the target table are updated) |
Usage notes
- When a FROM clause contains a JOIN between tables (e.g. t1 and t2), a target row in t1 may join against (i.e. match) more than one row in table t2. When this occurs, the target row is called a multi-joined row. When updating a multi-joined row, the ERROR_ON_NONDETERMINISTIC_UPDATE session parameter controls the outcome of the update: If FALSE (default value), no error is returned and one of the joined rows is used to update the target row; however, the selected joined row is nondeterministic.
- IF TRUE, an error is returned, including an example of the values of a target row that joins multiple rows.
- To set the parameter:
- If error logging is turned on for the target table, a supported error, such as a NOT NULL or CHECK constraint violation, doesn’t cause the statement to fail. Instead, the statement records the error in the table’s error table, leaves the row that caused the error unchanged, and updates the other rows. For more information, see Error logging for DML statements.