UPDATE:

This SQL command changes data in existing rows, either by adding new data or by modifying existing data. The syntax for this command is

UPDATE {table_name | view_name}

SET [{table_name | view_name}] {column_list | variable_list}

... [, {column_listN | variable_listN | variable_and_column_listN}]]

[WHERE clause]

where

table_name | view_name = [[database_name.]owner.]{table_name | view_name}

Specifies the name of the table or view used in the UPDATE statement. If the table or view is not in the current database, use a fully qualified table_name or view_name (database_name.owner.object_name).

SET:Is a required keyword used to introduce the list of column or variable clauses to be updated. When more than one column name and value pair are listed, separate the names with commas.

column_list = column_name = {expression | DEFAULT | NULL}

variable_list =variable_name = {expression | NULL}

column_name:Specifies a column from the table (table_name) or view (view_name).

WHERE clause = WHERE {search_conditions | CURRENT OF cursor_name}

Is used to perform a searched update (using search_conditions) or a positioned update (using CURRENT OF cursor_name). When no WHERE clause is given in the UPDATE statement, all rows in the table are modified.

Remarks

Use the UPDATE statement to change single rows, groups of rows, or all rows in a table. UPDATE specifies which row(s) to change and provides the new data. When updating rows, these rules apply:

· Updating a column with an empty string (' ') into a varchar or text column inserts a single space. All char columns are right-padded to the defined length.

· Modifying a text column with UPDATE initializes it, assigns a valid text pointer to it, and allocates at least one 2K data page (even if updating the column with NULL). For details about updating text or image fields, see the Text and Image Manipulation topic.

Note The UPDATE statement is logged; if you are replacing or modifying large blocks of text or image data, use the WRITETEXT or UPDATETEXT statement instead of the UPDATE statement. The WRITETEXT and UPDATETEXT statements (by default) are not logged. For details, see the Text and Image Manipulation topic.

Examples

A. UPDATE Statement with Only the SET Clause

These examples show how all rows can be affected if a WHERE clause is eliminated from an UPDATE statement.

In this example, if all the publishing houses in the publishers table move their head offices to Atlanta, Georgia, this is how the publishers table could be updated:

UPDATE publishers

SET city = 'Atlanta', state = 'GA'

This example changes the date and time for a specific id number 13 on a Friday(spooky):

UPDATE tbl_time

SET char_day='Friday',char_date='08/13/99',char_time='12:00:00'

WHERE int_id=13

Back to the homepage