Using COMMIT
Go Up to Ending a Transaction
Use COMMIT
to write transaction changes permanently to a database.
COMMIT
closes the record streams associated with the transaction, resets the transaction name to zero, and frees system resources assigned to the transaction for other uses. The complete syntax for COMMIT
is:
EXEC SQL COMMIT [TRANSACTION name] [RETAIN [SNAPSHOT] | RELEASE dbhandle [, dbhandle ...]]
For example, the following C code fragment contains a complete transaction. It gives all employees who have worked since December 31, 1992, a 4.3% cost-of-living salary increase. If all qualified employee records are successfully updated, the transaction is committed, and the changes are actually applied to the database.
. . .
EXEC SQL
SET TRANSACTION SNAPSHOT TABLE STABILITY;
EXEC SQL
UPDATE EMPLOYEE
SET SALARY = SALARY * 1.043
WHERE HIRE_DATE < '1-JAN-1993';
EXEC SQL
COMMIT;
. . .
By default, COMMIT
affects only the default transaction, GDS__TRANS
. To commit another transaction, use its transaction name as a parameter to COMMIT
.
Even
READ ONLY
transactions that do not change a database should be ended with a COMMIT
rather than ROLLBACK
. The database is not changed, but the overhead required to start subsequent transactions is greatly reduced.