Pervasive logo

Prev SQL Engine Reference Next

COMMIT


The COMMIT statement signals the end of a logical transaction and converts temporary data into permanent data. The logical transaction begins with START TRANSACTION. COMMIT must always be paired with START TRANSACTION. START TRANSACTION must always be paired with a COMMIT or a ROLLBACK.

Syntax

COMMIT [WORK] 

Remarks

COMMIT (and START TRANSACTION) is supported only within stored procedures. You cannot use COMMIT or START TRANSACTION within the SQL Data Manager. (The SQL Data Manager sets AUTOCOMMIT to "on.")

Any committed statements within a stored procedure are controlled by the outermost transaction of the calling ODBC application. This means that, depending on the AUTOCOMMIT mode specified on SQLSetConnectOption, calling the stored procedure externally from an ODBC application performs one of two actions. It either commits automatically (AUTOCOMMIT on, the default) or waits for you to call SQLTransact with SQL_COMMIT or SQL_ROLLBACK (when AUTOCOMMIT is set to off).

You may call multiple START TRANSACTION statements to start the nested transactions, but the outermost COMMIT controls whether any nested committed blocks are committed or rolled back. For example, if transactions are nested five levels, then five COMMIT statements are needed to commit all of the transactions. COMMIT does not release any lock until the outermost transaction is committed.

COMMIT and COMMIT WORK perform the same functionality.

Examples

The following example, within a stored procedure, begins a transaction which updates the Amount_Owed column in the Billing table. This work is committed; another transaction updates the Amount_Paid column and sets it to zero. The final COMMIT WORK statement ends the second transaction.

Statements are delimited with a semi-colon inside stored procedures and triggers.

START TRANSACTION; 
UPDATE Billing B 
SET Amount_Owed = Amount_Owed - Amount_Paid 
WHERE Student_ID IN 
(SELECT DISTINCT E.Student_ID 
FROM Enrolls E, Billing B 
WHERE E.Student_ID = B.Student_ID); 
COMMIT WORK; START TRANSACTION; UPDATE Billing B
SET Amount_Paid = 0 
WHERE Student_ID IN 
(SELECT DISTINCT E.Student_ID 
FROM Enrolls E, Billing B 
WHERE E.Student_ID = B.Student_ID); 
COMMIT WORK;

See Also

CREATE PROCEDURE

ROLLBACK

START TRANSACTION

 

Prev
CLOSE
Contents
Up
Check for Revisions
Next
CREATE GROUP