Console - COMMIT

Closes a transaction, committing the changes you have made to the database. Use the BEGIN command to open a transaction. If you don’t want to save the changes you’ve made, use the ROLLBACK command to revert the database state back to the point where you opened the transaction.

For more information, see Transactions.

Syntax

  1. COMMIT

Example

  • Initiate a transaction, using the BEGIN command:

    1. orientdb> BEGIN
    2.  
    3. Transaction 2 is running
  • For the sake of example, attempt to open another transaction:

    1. orientdb> BEGIN
    2.  
    3. Error: an active transaction is currently open (id=2). Commit or rollback
    4. before starting a new one.
  • Insert data into the class Account, using an INSERT statement:

    1. orientdb> INSERT INTO Account (name) VALUES ('tx test')
    2.  
    3. Inserted record 'Account#9:-2{name:tx test} v0' in 0,000000 sec(s).
  • Commit the transaction to the database:

    1. orientdb> COMMIT
    2.  
    3. Transaction 2 has been committed in 4ms
  • Display the new content, using a SELECT query:

    1. orientdb> SELECT FROM Account WHERE name LIKE 'tx%'
    2.  
    3. ---+---------+----------
    4. # | RID | name
    5. ---+---------+----------
    6. 0 | #9:1107 | tx test
    7. ---+---------+----------
    8.  
    9. 1 item(s) found. Query executed in 0.041 sec(s).

When a transaction is open, all new records use a temporary Record ID that features negative numbers. After the commit, they have a permanent Record ID that uses with positive numbers.

For more information, see