Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.2.1 |  CUBRID 8.3.0 |  CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 

UPDATE

Description

Use the UPDATE statement to update the existing data inserted.

Syntax

UPDATE table_name
SET assignment [ {, assignment }... ]
[ WHERE search_condition ] [ ; ]

assignment:
(attribute_name_comma_list) = { (expression_comma_list) | (select_stmt)}

  • table_name : Specifies the name of the table whose columns are to be updated.
  • attribute_name : Specifies the columns to be updated.
  • expression : Specifies a new value to be updated or NULL in the column.
  • select_stmt : A query result can be used for the update operation. However, the query must return only one instance as a result. Also, the number of columns in the query result and the number of the columns specified in attribute_name must be same.
  • search_condition : By using the WHERE Clause, you can limit the operation so that only instances that meet the search_condition will be updated.
Note

One column can be updated only once in the same UPDATE statement.

Example
  • Example 1
  • The following is an example of changing the capital city of Korea to Busan in the nation table.

UPDATE nation SET capital ='Busan' WHERE name = 'Korea';

  • Example 2
  • The following is an example of inserting the information about Lim Su-jeong, a 2008 Beijing Olympics gold medalist in women's Taekwondo into the athlete table and updating the athlete's nationality with the query result.

INSERT INTO athlete(name, gender, event) VALUES ('Lim Su-jeong','W','Taekwondo');

UPDATE athlete SET nation_code = (SELECT code FROM nation WHERE name = 'Korea') WHERE name = 'Lim Su-jeong';