Transactions 

A transaction is a sequence of sql statements that are handled by the database system as a basic unit, in the sense that any modifications made to the database by the sql statements are either all reflected in the state of the database, or else none of the database modifications are retained.

The first transaction is opened when a session is opened with the CONNECT statement. The transaction is concluded with the COMMIT statement or the ROLLBACK statement. When a transaction is successfully concluded with a commit statement, all of the changes to the database are retained. If a transaction is aborted using a rollback statement, on the other hand, or if it is aborted in another way, all of the changes to the database made by the transaction are rolled back.

Both the COMMIT and ROLLBACK statements open a new transaction implicitly.

Locks

Since the database system permits concurrent transactions on the same database objects, locks on rows, tables, and the catalog are necessary to isolate individual transactions. These locks are set either implicitly by the database system while an SQL statement is being processed or explicitly using the LOCK statement. The locks are assigned to the transaction that contains the sql statement or lock statement. The database system distinguishes between SHARE locks and exclusive locks, which refer either to rows or tables, and optimistic row locks. In addition, there are special locks for the metadata of the catalog. These locks, however, are always set implicitly.

EXCLUSIVE locks for rows that have not yet been modified and SHARE locks on rows can be released by the UNLOCK statement before the end of the transaction.

The locks assigned to a transaction are usually released at the end of the transaction, making the respective database objects accessible again to other transactions.

The following table contains an overview of the possible parallel locks. EXCL stands for an exclusive lock and SHARE for a SHARE lock.

A lock collision exists in the cases which are marked with "No"; i.e., after having requested a lock within a transaction, the user must wait for the lock to be released until one of the above situations or one of the situations that are marked with "Yes" in the matrix occurs.

Subtransactions

The SQL statements SUBTRANS BEGIN, SUBTRANS END, and SUBTRANS ROLLBACK (SUBTRANS statement) subdivide a transaction into additional basic units. These can be nested as often as necessary and in any form. Unlike transactions, however, modifications made by subtransactions can be reversed by a the rollback statement or a SUBTRANS ROLLBACK of a higher-level subtransaction, even after the subtransaction has been concluded with SUBTRANS END.

 

SQL statements for transaction management

CONNECT statement

SET statement

 

COMMIT statement

ROLLBACK statement

SUBTRANS statement

LOCK statement

UNLOCK statement

RELEASE statement