Similar to RDBMS, OrientDB also provides transaction concepts like Commit and Rollback. Commit refers to closing the transaction by saving all changes to the database. Rollback refers to recovering the database state to the point where you opened the transaction.
The following statement is the basic syntax of the Commit database command.
COMMIT
Note − You can use this command only after connecting to a particular database and after beginning the transaction.
Example
In this example, we will use the same database named ‘demo’ that we created in the previous chapter. We will see the operation of commit transaction and store a record using transactions.
First, start the transaction using the following BEGIN command.
orientdb {db = demo}> BEGIN
Then, insert a record into an employee table with the values id = 12 and name = satish.P using the following command.
orientdb> INSERT INTO employee (id, name) VALUES (12, 'satish.P')
You can use the following command to commit the transaction.
orientdb> commit
If this transaction is successfully committed, you will get the following output.
Transaction 2 has been committed in 4ms