The SQL UPDATE Statement

An SQL UPDATE statement changes the values of columns in the existing rows of a table. If the UPDATE activity is successful, it returns the number of rows changed in the table.

If the UPDATE activity is not successful, 0 is returned as the number of rows changed in the table.

Transactions are not supported for UPDATE statements and you cannot create an UPDATE statement from a transacted session.

Since transactions are not supported with UPDATE, if an error occurs while performing a row update, any rows already updated remain changed and the update is not rolled back.

Syntax

UPDATE <table_name> [ AS <alias> ] <SET clause> [ <WHERE clause> ]

Where

  • table_name: The name of the table containing the rows to be updated.
  • alias: A temporary name for the table that is used to make the table name more readable.
  • SET clause: Begins with the keyword 'SET' and contains a comma-separated list of assignments where column names are set to value expressions. For example,
    •  SET column1 = value1
    • SET column1 = value1, column2 = value2

    • SET (column1, column2) = (value1, value2)

  • WHERE clause: An expression that starts with the keyword 'WHERE' and results in a boolean value that indicates whether a row should be updated. If omitted, all rows of the table are updated. For more information, see The WHERE Clause.