Skip to content

UPDATE

UPDATE modifies specified rows in the target table with new values.

Syntax

sql
UPDATE target_tab
       SET col_name = value [, col_name=value, ...]
       [WHERE cond]

Parameters

target_tab: The name of the target table (or target object).


col_name: The name of the column to be updated in the target table. The column name must not be prefixed with the table name. Example: UPDATE my_table1 SET my_table1.col1 = 1 will cause an error.


value: A value or expression to assign to the specified column.


WHERE cond (optional): Filters the rows to be updated. If the UPDATE statement has no WHERE clause, all rows in the target table will be updated.

Example

sql
create table  mkw_doku.my_table1 (ord string, col1 integer, col2 integer);

insert into mkw_doku.my_table1 (select 'a' as ord, 10 as col1, 1 as col2
                                union all 
                                select 'b' as ord, 20 as col1, 2 as col2
                                union all
                                select 'c' as ord, 30 as col1, 3 as col2);

update mkw_doku.my_table1 tar                                  
  set ord = ord || ' updated' where col2 = 1 or col2 = 3;      

select * from mkw_doku.my_table1;
+-----------+------+------+ 
| ord       | col1 | col2 | 
+-----------+------+------+ 
| a updated | 10   | 1    | 
| b         | 20   | 2    | 
| c updated | 30   | 3    | 
+-----------+------+------+