COMMIT - Teradata Database

SQL Data Manipulation Language

Product
Teradata Database
Release Number
15.10
Language
English (United States)
Last Update
2018-10-06
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata® Database

Terminates the current ANSI session mode SQL transaction, commits all changes made within it, and drops the Transient Journal for the transaction.

where:

 

Syntax Element …

Specifies …

WORK

that if the SQL Flagger is enabled, the absence of WORK causes the request to be flagged.

For information about the SQL Flagger, see SQL Fundamentals.

RELEASE

the connection between the client application program and the Teradata Database, whether implicit or explicit, is to be terminated.

This option applies to embedded SQL only and is not ANSI‑compliant.

COMMIT is ANSI SQL:2011-compliant with an extension.

COMMIT is valid only in ANSI session mode. If used in Teradata session mode, it returns a failure and aborts the transaction.

Other SQL dialects support similar non‑ANSI standard statements with names such as the following:

  • COMMIT TRANSACTION
  • COMMIT WORK
  • None.

    In ANSI session mode, the first SQL request in a session initiates a transaction. The transaction is terminated by sending either a COMMIT or a ROLLBACK/ABORT request. Request failures do not cause a rollback of the transaction, only of the request that causes them.

    There are no implicit transactions in ANSI session mode. More accurately, each ANSI transaction is initiated implicitly, but always completed explicitly. The COMMIT must always be explicitly stated and be the last request of a transaction in order for the transaction to terminate successfully.

    In ANSI session mode, you must issue a COMMIT (or ABORT/ROLLBACK) even when the only request in a transaction is a SELECT or SELECT AND CONSUME.

    In the case of a SELECT request, it makes no difference whether you issue a COMMIT or an ABORT/ROLLBACK.

    In the case of a SELECT AND CONSUME, there is a difference in the outcomes between issuing a COMMIT or ABORT/ROLLBACK because an ABORT or ROLLBACK request reinstates the subject queue table of the request to its former status, containing the rows that were pseudo‑consumed by the aborted SELECT AND CONSUME request.

    The following rules apply to the COMMIT statement within an embedded SQL application:

  • COMMIT cannot be performed as a dynamic SQL statement.
  • COMMIT discards dynamic SQL statements prepared within the current transaction.
  • COMMIT closes open cursors.
  • COMMIT is valid only when you specify the TRANSACT(COMMIT), -tr(COMMIT), TRANSACT(ANSI), or ‑tr(ANSI) options to the preprocessor.
  • Its use causes an error if the program is precompiled with the TRANSACT(BTET), ‑tr(BTET), or the TRANSACT(2PC) preprocessor options.

  • If you specify the RELEASE option, then the application program connection to Teradata Database (whether explicit or implicit) is terminated.
  • If additional SQL requests (other than CONNECT or LOGON) are then performed, an implicit connection is attempted.

  • RELEASE is not valid when you specify the TRANSACT(ANSI) or -tr(ANSI) options to the preprocessor.
  • The ABORT and ROLLBACK statements also cause the current transaction to be terminated, but with rollback rather than commit. See “ABORT” on page 277 and “ROLLBACK” on page 462.

    If you use COMMIT in a BTEQ script with either the .SESSION or the .REPEAT command, you must send the COMMIT request along with the repeated SQL request as one request.

    If you send the repeated request without the COMMIT, one of the requests is eventually blocked by other sessions and the job hangs because of a deadlock.

    The following dummy example illustrates how this should be done:

         .SESSION TRANS ANSI
         .SESSIONS 10
         .LOGON TDPID/USER,PASSWD
     
         .IMPORT DATA FILE = data_file_name
         .REPEAT I
     
         USING i(INTEGER), j(INTEGER)
         INSERT INTO table_name (col1, col2)
         VALUES (:1, :j); COMMIT;
     
         .QUIT