update

Description

Modifies data in rows of a table.

Syntax

exec sql [at connection_name] update table_name 
 set [table_name] 
     column_name1 = {expression1 
         | NULL | (select_statement)}
     [, column_name2 =
     {expression2 | NULL
         | (select_statement)}]… 
 [from table_name 
     [, table_name]… 
 [where {search_conditions | current of cursor_name}]; 

Parameters

table_name

The name of a table or view, specified in any format that is valid for the update statement in Transact-SQL.

Examples

Example 1

exec sql begin declare section; 
     CS_CHAR       store_name[40]; 
     CS_CHAR       disc_type[40]; 
     CS_INT        lowqty; 
     CS_INT        highqty; 
     CS_FLOAT      discount; 
 exec sql end declare section;  
 
 CS_CHAR      answer[1]);  
 
 exec sql declare update_cursor cursor for     
     select s.stor_name, d.discounttype, 
     d.lowqty, d.highqty, d.discount      
     from   stores s, discounts d
     where  d.stor_id = s.stor_id;
 
 exec sql open update_cursor;  
 
 exec sql whenever not found goto alldone;
 
 while (TRUE) {
     exec sql fetch update_cursor into
         :store_name, :disc_type, :lowqty,
         :highqty, discount; 
     print store_name, disc_type, lowqty,
         highqty, discount; 
     printf("New discount? ");
     gets(discount);
    exec sql update discounts 
         set discount = :discount 
         where current of update_cursor; 
 }
 
 alldone: 
 exec sql close update_cursor; 
 exec sql disconnect all;

Usage

See also

close, delete cursor, fetch, open, prepare