UPDATE
Purpose
Using the UPDATE the statement, you can make targeted changes to the contents of the table.
Prerequisites
-
You need either the system privilege
USE ANY SCHEMAor the object privilegeUSAGEon the target schema, or the schema must be owned by you or one of your assigned roles. - You need either the system privilege
UPDATE ANY TABLEor the object privilegeUPDATEon the table or its schema, or the table must be owned by you or one of your assigned roles. - You need the appropriate
SELECTprivileges on the schema object referenced in the optionalFROMclause.
Syntax
update::=
Usage Notes
- By using the
FROMclause, you can define several tables which are joined through theWHEREclause. By that, you can specify complex update conditions which are similar to complexSELECTstatements. The updated table must be specified from within theFROMclause. - If a column is set to the value
DEFAULT, then the rows in this column affected by theUPDATEare filled automatically. For identity columns, a monotonically increasing number is generated, and for columns, with default values their respective default value is used. For all other columns, the valueNULLis used. - For information on default values, refer to Default Values section. For information on identity columns, refer to the Default Values section.
- The
PREFERRINGclause defines a Skyline preference term. For more information, refer to the Skyline section.
Internally this statement is transformed into a MERGE statement. Therefore, error messages can refer to the MERGE command. If one row is updated multiple times, the new value must be identical. Otherwise, the error message "Unable to get a stable set of rows in the source tables" will be displayed.
Examples
--Salary increase by 10%
UPDATE staff SET salary=salary*1.1 WHERE name='SMITH';
--Euro conversion
UPDATE staff AS U SET U.salary=U.salary/1.95583, U.currency='EUR'
WHERE U.currency='DM';
--Complex UPDATE using a join with another table
UPDATE staff AS U
SET U.salary=V.salary, U.currency=V.currency
FROM staff AS U, staff_updates AS V
WHERE U.name=V.name;