Using the UPDATE the statement, you can make targeted changes to the contents of the table.
- You need to have the system privilege UPDATE ANY TABLE, object privilege UPDATE on the table or its schema, or the table belongs to the current user or one of the user roles.
- You need to have the appropriate SELECT privileges on the schema object referenced in the optional FROM clause.
- By using the FROM clause, you can define several tables which are joined through the WHERE clause. By that, you can specify complex update conditions which are similar to complex SELECT statements. The updated table must be specified from within the FROM clause.
- If a column is set to the value DEFAULT, then the rows in this column affected by the UPDATE are 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 value NULL is used.
- For information on default values, refer to Default Values section. For information on identity columns, refer to the Default Values section.
- The PREFERRING clause 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.
--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;