Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.2.1 |  CUBRID 8.3.0 |  CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 

Transaction Commit

Description

Updates that occurred in the database are not permanently stored until the COMMIT WORK statement is executed. "Permanently stored" means that storing the updates in the disk is completed; The WORK keyword can be omitted. In addition, other users of the database cannot see the updates until they are permanently applied. For example, when a new instance is inserted into a table, only the user who inserted the instance can access it until the database transaction is committed. (If the UNCOMMITTED INSTANCES isolation level is used, other users can see inconsistent uncommitted updates.)

All locks obtained by the transaction are released after the transaction is committed.

Syntax

[;]COMMIT [ WORK ]

If you place a semicolon (;) before the statement, the statement is considered as a session command and is executed immediately. If you don't, the statement is considered as a query statement and the execution is delayed until ;x[run] is executed.

Example

The database transaction in the following example consists of three UPDATE statements and changes three column values of seats from the stadium table. To compare the results, check the current values and names before the update is made. Since, by default, csql runs in an autocommit mode, the following example is executed after setting the autocommit mode to off.

;autocommit off
AUTOCOMMIT IS OFF
select name, seats
from stadium where code in (30138, 30139, 30140);
;xrun
=== <Result of SELECT Command in Line 1>===
    name                        seats
==================================
    'Athens Olympic Tennis Centre'         3200
    'Goudi Olympic Hall'         5000
    'Vouliagmeni Olympic Centre'         3400
3 rows selected.

The three UPDATE statements must have the current values of seats in each stadium. After the command is executed, you can retrieve related columns of the seats table to find out whether the data is inserted correctly.

update stadium
set seats = seats + 1000
where code in (30138, 30139, 30140);
;xrun
3 rows updated.
select name, seats from stadium where code in (30138, 30139, 30140);
;xrun
=== <Result of SELECT Command in Line 1>===
    name                        seats
===================================
    'Athens Olympic Tennis Centre'         4200
    'Goudi Olympic Hall'         6000
    'Vouliagmeni Olympic Centre'         4400
 
3 rows selected.

If updates are made correctly, you can make them permanent by using the following COMMIT WORK statement.

;commit work

Note If the application exits the database without committing the transaction when the autocommit mode is off, all updates made after the last COMMIT WORK are automatically rolled back. Therefore, CSQL Interpreter performs a procedure to check whether the transaction should be committed or aborted. For the AUTOCOMMIT session command, see Session Commands.