begin transaction

Description

Marks the starting point of an unchained transaction.

Syntax

exec sql [at connection_name] 
 begin {transaction | tran} [transaction_name]; 

Parameters

transaction | tran

The keywords transaction and tran are interchangeable.

transaction_name

The name that you are assigning to this transaction. The name must conform to the rules for Transact-SQL identifiers.

Examples

Example 1

/*
 ** 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;

Usage

See also

commit transaction, commit work, rollback transaction, rollback work