Ends a transaction, preserving changes made to the database during the transaction.
exec sql [at connection_name] commit [transaction | tran | work] [transaction_name];
The keywords transaction, trans, and work are interchangeable in the rollback statement, except that only work is ANSI-compliant.
A name assigned to the transaction.
/*
** Using chained transaction mode,
** synchronize tables on two servers
*/
exec sql begin declare section;
char title_id[7];
int num_sold;
exec sql end declare section;
long SQLCODE;
...
try_update:
exec sql whenever sqlerror goto abort_tran;
exec sql at connect1 select sum(qty)
into :num_sold
from salesdetail
where title_id = :title_id;
exec sql at connect2 update current_sales
set num_sold = :num_sold
where title_id = :title_id;
exec sql at connect2 commit work;
exec sql at connect1 commit work;
return;
abort_tran:
printf("oops, should have used 2-phase commit\n");
exec sql whenever sqlerror continue;
exec sql at connect2 rollback work;
exec sql at connect1 rollback work;
goto try_update;
This reference page mainly describes aspects of the Transact-SQL commit statement that differ when used with Embedded SQL. See the Adaptive Server Enterprise Reference Manual for more information about commit and Transact-SQL transaction management.
Transaction names must conform to the Transact-SQL rules for identifiers. Transaction names are a Transact-SQL extension: they cannot be used with the ANSI-compliant keyword work.
When nesting transactions, assign a transaction name only to the outermost begin transaction statement and its corresponding commit transaction or rollback transaction statement.
begin transaction, commit work, rollback transaction, rollback work