Console - BEGIN

Initiates a transaction. When a transaction is open, any commands you execute on the database remain temporary. In the event that you are satisfied with the changes, you can call the COMMIT command to commit them to the database. Otherwise, you can call the ROLLBACK command, to roll the changes back to the point where you called BEGIN.

Syntax:

  1. BEGIN

Examples

  • Begin a transaction:

    1. orientdb> BEGIN
    2.  
    3. Transaction 1 is running
  • Attempting to begin a transaction when one is already open:

    1. orinetdb> BEGIN
    2.  
    3. Error: an active transaction is currently open (id=1). Commit or rollback
    4. before starting a new one.
  • Making changes when a transaction is open:

    1. orientdb> INSERT INTO Account (name) VALUES ('tx test') SELECT FROM Account WHERE name LIKE 'tx%'
    2.  
    3. ---+-------+----------
    4. # | RID | name
    5. ---+-------+----------
    6. 0 | #9:-2 | tx test
    7. ---+-------+----------

When a transaction is open, new records all have temporary Record ID’s, which are given negative values, (for instance, like the #9:-2 shown above). These remain in effect until you run COMMIT

For more information on Transactions, see