The SET
Clause
In the SET
clause, the assignment expressions, containing the columns with the values to be set, are separated by commas.In an assignment expression, column names are on the left and the values or expressions to assign are on the right.A column may be assigned only once in the SET
clause.
A column name can be used in expressions on the right.The old value of the column will always be used in these right-side values, even if the column was already assigned a new value earlier in the SET
clause.
Using the expression DEFAULT
will set the column to its default value (either NULL
or the value specified on the DEFAULT
clause of the column definition).For an identity column, specifying DEFAULT
will generate a new identity value.It is possible to “update” calculated columns in the SET
clause if and only if the assigned value is DEFAULT
.
Note
|
It is not possible to assign |
Data in the TSET
table:
A B
---
1 0
2 0
The statement:
UPDATE tset SET a = 5, b = a;
will change the values to:
A B
---
5 1
5 2
Notice that the old values (1 and 2) are used to update the b column even after the column was assigned a new value (5).