UPDATE
Modifies rows in an existing table.
Synopsis
Description
The UPDATE
command modifies the values of specific columns in all rows that satisfy the command condition.
Parameters
table_name
The name of the table to modify its rows.
alias
A substitute alias name for table_name
. The alias name should match the Identifiers Limitations.
SET
The requested change. Contains a tuple of column names and a tuple of their new values.
column_name
The name(s) of the column(s) to modify. The columns should not include the table name (SET tab1.c_id = 1
is invalid).
expression
The new value to replace the existing value per column.
DEFAULT
Set the new column value to the column default value as set for the column in the table definition.
sub-SELECT
Subquery that returns exactly one row. The subquery returned columns should match the SET
clause columns and their data types.
Note: If the subquery returns no rows, the value of all the updated columns in the updated rows is set to NULL.
WHERE
A filter to decide which rows in the table to update. If no condition is set, all the rows in the table are updated.
The WHERE
clause can contain the rows ROWID
with ‘=’ or ‘IN
(<
list of literals>
)’
condition.
RETURNING output_expression
Returns the given expression for every row modified by the command. Refer to the expression
parameter of SELECT for specification of the output_expression parameter.
Outputs
On successful completion, the UPDATE
command returns the count of the updated rows.
Examples
Update the rows based on a simple predicate:
Update multiple columns and return the update rows ROWIDs:
Update a table based on ROWID
Update a table using a result from a non-correlated subquery
Compatibility
The UPDATE
command conforms to the SQL standard with the exception of the RETURNING functionality.