UPDATE Syntax
5 to have a new manager, with
ID 3, and to have a 10% salary increase:
UPDATE Example
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
SET clause:
UPDATE with Subquery in SET Clause Example
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.INNER JOIN:
UPDATE with JOIN Clause Example
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 theSET 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.
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 theKI_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.
UPDATE Ignore Duplicates Example