The COMMIT statement ends a unit of work and commits the database changes that were made by that unit of work.
This statement can be embedded in an application program or issued interactively. It is an executable statement that can be dynamically prepared.
COMMIT is not allowed in a trigger if the trigger program and the triggering program run under the same commitment definition. COMMIT is not allowed in a procedure if the procedure is called on a connection to a remote application server or if the procedure is defined as ATOMIC. COMMIT is not allowed in a function.
None required.
.-WORK-. >>-COMMIT--+------+--+------+---------------------------------->< '-HOLD-'
The COMMIT statement ends the unit of work in which it is executed and starts a new unit of work. It commits all changes made by SQL schema statements (except DROP SCHEMA) and SQL data change statements during the unit of work. For information on SQL schema statements and SQL data change statements see Table 36 and Table 37.
Connections in the release-pending state are ended.
All implicitly acquired locks are released; except for object level locks required for the cursors that are not closed.
All locators that are not held are released. For more information on held locators, see HOLD LOCATOR.
Recommended coding practices: An explicit COMMIT or ROLLBACK statement should be coded at the end of an application process. Either an implicit commit or rollback operation will be performed at the end of an application process depending on the application environment. Thus, a portable application should explicitly execute a COMMIT or ROLLBACK before execution ends in those environments where explicit COMMIT or ROLLBACK is permitted.
An implicit COMMIT or ROLLBACK may be performed under the following circumstances.
Effect of commit: Commit without HOLD causes the following to occur:
For existing connections:
Row lock limit: A unit of work can include the processing of up to 4 million rows, including rows retrieved during a SELECT or FETCH statement61, and rows inserted, deleted, or updated as part of INSERT, DELETE, and UPDATE statements.62
Unaffected statements: The commit and rollback operations do not affect the DROP SCHEMA statement, and this statement is not, therefore, allowed in an application program that also specifies COMMIT(*CHG), COMMIT(*CS), COMMIT(*ALL), or COMMIT(*RR).
Commitment definition use: The commitment definition used by SQL is determined as follows:
In a C program, transfer a certain amount of commission (COMM) from one employee (EMPNO) to another in the EMPLOYEE table. Subtract the amount from one row and add it to the other. Use the COMMIT statement to ensure that no permanent changes are made to the database until both operations are completed successfully.
void main () { EXEC SQL BEGIN DECLARE SECTION; decimal(5,2) AMOUNT; char FROM_EMPNO[7]; char TO_EMPNO[7]; EXEC SQL END DECLARE SECTION; EXEC SQL INCLUDE SQLCA; EXEC SQL WHENEVER SQLERROR GOTO SQLERR; ... EXEC SQL UPDATE EMPLOYEE SET COMM = COMM - :AMOUNT WHERE EMPNO = :FROM_EMPNO; EXEC SQL UPDATE EMPLOYEE SET COMM = COMM + :AMOUNT WHERE EMPNO = :TO_EMPNO; FINISHED: EXEC SQL COMMIT WORK; return; SQLERR: ... EXEC SQL WHENEVER SQLERROR CONTINUE; /* continue if error on rollback */ EXEC SQL ROLLBACK WORK; return; }