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 row is inserted into a class, only the user who inserted the row 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. 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.

update stadium

set seats = seats + 1000

where code in (30138, 30139, 30140);

;xrun

3 rows affected.

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.

;commit work

Note In CUBRID, an auto-commit mode is set by default for transaction management. An auto-commit mode is a mode that commits or rolls back all SQL statements. The transaction is committed automatically if the SQL is executed successfully, or is rolled back automatically if an error occurs.
Such auto commit modes are supported in CUBRID JDBC, ODBC, OLEDB and the CSQL Interpreter. In CUBRID CCI and CUBRID PHP, auto commit modes can be applied only for SELECT statements by setting broker parameters. For details, see Parameter by Broker. For a session command (;AUtocommit) that sets the auto-commit mode in the CSQL interpreter, see Session Commands.