O'Reilly logo

SQL in a Nutshell by Kevin Kline

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

UPDATE Statement

Synopsis

The UPDATE statement changes existing data in a table. Use great caution when issuing an UPDATE statement without a WHERE clause, since the statement then affects every row in the entire table.

Platform

Command

DB2

Supported, with variations

MySQL

Supported, with variations

Oracle

Supported, with variations

PostgreSQL

Supported, with variations

SQL Server

Supported, with variations

SQL2003 Syntax

UPDATE [ONLY] {table_name | view_name}
SET {{column_name = { ARRAY [array_val [,...] ] | DEFAULT |
   NULL | scalar_expression},
      column_name = { ARRAY | DEFAULT |
   NULL | scalar_expression}
      [,...] }
    | ROW = row_expression }
[ WHERE search_condition | WHERE CURRENT OF cursor_name ]

Keywords

ONLY

Restricts cascading of the updated values to any subtables of the target table or view. ONLY effects only typed (object-oriented) tables and views. If used with a nontyped table or view, it causes an error.

table_name | view_name

The target table or view of the update statement. You need appropriate permissions on the target according to the rules of the platform. Updates against views often have special rules. Generally, it is only advisable to perform an UPDATE against a view if the view is representative of a single table.

SET

Assigns a specific value to a column or row.

column_name

Used in conjunction with SET, as in SET column1= 'foo'. Allows you to set a new value for the specified column. You can update as many columns as you like in one statement, though you ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required