Description:
Change values in the existing table record.
Syntax:
UPDATE table_name
SET column_name = expression |
NULL |
DEFAULT ] [, ...]
[
FROM table_source ]
[
WHERE search_condition ]
table_name |
Name of the table. |
column_name |
Column name into which a new value will be entered. |
expression |
The own value for the appropriate column determined by an expression. |
table_source |
Name of the table that will be used for obtaining criteria of changing values. |
search_condition |
Logical expression specifies which rows of the table are being changed (if WHERE is not stated, then it means all records). |
Example1:
Change the value of the column 'flags' for all records to the value 1.
UPDATE data SET flags=1
Example2:
Change the value of the column 'flags' for the record that is specified by the precise time to the value 2.
UPDATE data SET flags=2 WHERE time='2003-07-02 10:02:00.227'
Example3:
Change the value of the column 'flags' for the first record that meets the criterion that the 'time' value is greater than the specified time.
UPDATE data SET flags=3 FROM (SELECT TOP 1 * FROM data ORDER BY time) AS d1 WHERE data.time=d1.time