Skip to main content
Updates can set columns to specified constant values or expressions.
UPDATE Syntax
For example, to update employee with ID 5 to have a new manager, with ID 3, and to have a 10% salary increase:
UPDATE Example
Subqueries can be used in the expression list and within the SET clause. To update all the bottom earners in each department with a 5% salary increase using a subquery in the expression list:
UPDATE with Subquery in WHERE Clause Example
To update a backup table to match the source table that was just updated for new salary values using a subquery within the SET clause:
UPDATE with Subquery in SET Clause Example
Joins can be used within an UPDATE statement to update records based on the results of a JOIN.
The JOIN statement cannot be part of the SET clause. Also, primary key column updates are not supported using JOIN operations. The table to be updated must be in the FROM clause.
For example, to update a backup table to match the source table that was just updated for new manager and salary values using an INNER JOIN:
UPDATE with JOIN Clause Example
Simplified JOIN syntax is also supported:
UPDATE with JOIN Clause Alternate Example

Overwriting Duplicates

When updating the primary key value(s) of a record, it is possible for that updated record to collide with another record with the same primary key. To update the original record with the values specified in the SET clause and remove the other existing record with the same primary key, use the KI_HINT_UPDATE_ON_EXISTING_PK hint. If the target table has no primary key, this hint will be ignored.
This hint can be specified as the connection option UpdateOnExistingPk when using JDBC/ODBC.
UPDATE Overwrite Duplicates Example
By default, updates resulting in primary key collisions will be rejected, and the existing record(s) will remain unchanged. The KI_HINT_UPDATE_ON_EXISTING_PK hint overrides this behavior, favoring the original record being updated and the new values used to update it, specified in the SET clause, over the other existing record with the same primary key.

Ignoring Duplicates

When updating the primary key value(s) of a record, it is possible for that updated record to collide with another record with the same primary key. To discard updates that result in primary key collisions and not return an error, use the KI_HINT_IGNORE_EXISTING_PK hint. If the target table has no primary key or if using KI_HINT_UPDATE_ON_EXISTING_PK, this hint will be ignored.
These hints can be specified as connection options (IgnoreExistingPk, UpdateOnExistingPk) when using JDBC/ODBC.
UPDATE Ignore Duplicates Example