Marks the starting point of an unchained transaction.
exec sql [at connection_name] begin {transaction | tran} [transaction_name];
The keywords transaction and tran are interchangeable.
The name that you are assigning to this transaction. The name must conform to the rules for Transact-SQL identifiers.
/*
** Use explicit transactions to
** syncronize tables on two servers
*/
exec sql begin declare section;
char title_id[7];
int num_sold;
exec sql end declare section;
long sqlcode;
...
exec sql whenever sqlerror goto abort_tran;
try_update:
exec sql at connect1 begin transaction;
exec sql at connect2 begin transaction;
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 transaction;
exec sql at connect1 commit transaction;
if (sqlcode != 0)
printf("oops, should have used 2-phase
commit\n");
return;
abort_tran:
exec sql whenever sqlerror continue:
exec sql at connect2 rollback transaction;
exec sql at connect1 rollback transaction;
goto try_update;
This reference page describes aspects of the Transact-SQL begin transaction statement that differ when used with Embedded SQL. See the Adaptive Server Enterprise Reference Manual for more information about begin transaction and Transact-SQL transaction management.
The begin transaction statement is valid only in unchained transaction mode. In chained transaction mode, you cannot explicitly mark the starting point of a transaction.
When nesting transactions, assign a transaction name only to the outermost begin transaction statement and its corresponding commit transaction or rollback transaction statement.
Unless you set the database option ddl in tran, Adaptive Server does not allow the following statements inside an unchained transaction: create database, create table, create index, create view, drop, select into table_name, grant, revoke, alter database, alter table, truncate table, update statistics, reconfigure, load database, load transaction, and disk init.
A transaction includes only statements that execute on the connection that is current when the transaction begins.
Remote procedures execute independently of any transaction in which they are included.
commit transaction, commit work, rollback transaction, rollback work