COMMIT
statementEach statement within SurrealDB is run within its own transaction by default. If a set of changes need to be made together, then groups of statements can be run together as a single transaction, either succeeding as a whole, or failing without leaving any residual data modifications. A COMMIT
statement is used at the end of such a transaction to make the data modifications a permanent part of the database.
SurrealQL SyntaxCOMMIT [ TRANSACTION ];
The following query shows example usage of this statement.
BEGIN TRANSACTION;
-- Setup accounts
CREATE account:one SET balance = 135605.16;
CREATE account:two SET balance = 91031.31;
-- Move money
UPDATE account:one SET balance += 300.00;
UPDATE account:two SET balance -= 300.00;
-- Finalise all changes
COMMIT TRANSACTION;
The following two options can be used at any point if a transaction must be cancelled without commiting the changes: