Ending a Transaction
Go Up to Working with Transactions
When a transaction’s tasks are complete, or an error prevents a transaction from completing, the transaction must be ended to set the database to a consistent state. There are two statements that end transactions:
COMMITmakes a transaction’s changes permanent in the database. It signals that a transaction completed all its actions successfully.
ROLLBACKundoes a transaction’s changes, returning the database to its previous state, before the transaction started.
ROLLBACKis typically used when one or more errors occur that prevent a transaction from completing successfully.
ROLLBACK close the record streams associated with the transaction, reinitialize the transaction name to zero, and release system resources allocated for the transaction. Freed system resources are available for subsequent use by any application or program.
ROLLBACK have additional benefits. They clearly indicate program logic and intention, make a program easier to understand, and most importantly, assure that a transaction’s changes are handled as intended by the programmer.
ROLLBACK is frequently used inside error-handling routines to clean up transactions when errors occur. It can also be used to roll back a partially completed transaction prior to retrying it, and it can be used to restore a database to its prior state if a program encounters an unrecoverable error.
For more information about
COMMIT RELEASE, and
ROLLBACK RELEASE, see Working with Databases (Embedded SQL Guide).