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

You can update the column value of a record saved in the target table to a new one by using the UPDATE statement. Specify the name of the column to update and a new value in the SET clause, and specify the condition to be used to extract the record to be updated in the WHERE Clause. You can also specify the number of records to be updated in the LIMIT clause.  

Syntax

UPDATE table_name SET column_name = {expr | DEFAULT} [, column_name = {expr | DEFAULT]...]

    [WHERE search_condition]

    [LIMIT row_count]

  • table_name : Specify the name of the table to be updated.
  • column_name : Specify the columns to be updated.
  • expr | DEFAULT : Specify a new value for the column, and specify an expression or the DEFAULT keyword as the value. You can also specify the SELECT query, which returns a single result record.
  • search_condition : You can update the column value only for the record that satisfies the condition by specifying one in the WHERE Clause.
  •  row_count : Specify the number of records to be updated after the LIMIT Clause. An integer greater than 0 can be specified.
Remark

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

Example

--creating a new table having all records copied from a_tbl1

CREATE TABLE a_tbl5 AS SELECT * FROM a_tbl1;

SELECT * FROM a_tbl5 WHERE name IS NULL;

;xr

 

=== <Result of SELECT Command in Line 1> ===

 

           id  name                  phone

=========================================================

         NULL  NULL                  '000-0000'

            4  NULL                  '000-0000'

            5  NULL                  '000-0000'

            7  NULL                  '777-7777'

 

 

4 rows selected.

 

UPDATE a_tbl5 SET name='yyy', phone='999-9999' WHERE name IS NULL LIMIT 3;

SELECT * FROM a_tbl5;

;xr

 

=== <Result of SELECT Command in Line 1> ===

 

           id  name                  phone

=========================================================

         NULL  'yyy'                 '999-9999'

            1  'aaa'                 '000-0000'

            2  'bbb'                 '000-0000'

            3  'ccc'                 '333-3333'

            4  'yyy'                 '999-9999'

            5  'yyy'                 '999-9999'

            6  'eee'                 '000-0000'

            7  NULL                  '777-7777'

 

 

8 rows selected.