Modifies data in rows of a table.
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}];
The name of a table or view, specified in any format that is valid for the update statement in Transact-SQL.
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;
This reference page mainly describes aspects of the Transact-SQL update statement that differ when the statement is used in Embedded SQL. See the Adaptive Server Enterprise Reference Manual for more information about the update statement.
Host variables can appear anywhere in an expression or in any where clause.
You can use the where clause to update selected rows in a table. Omit the where clause to update all rows in the table. Use where current of cursor_name to update the current row of an open cursor.
When where current of cursor_name is specified, the statement must be executed on the connection specified in the open cursor statement. If the at connection_name clause is used, it must match the open cursor statement.
close, delete cursor, fetch, open, prepare