Outdated Version

You are viewing an older version of this section. View current production version.

BEGIN

Commits any existing open transaction on the current connection and starts a new transaction.

Syntax

START TRANSACTION | BEGIN [WORK]

Remarks

  • This command must be run on the master aggregator or a child aggregator node (see Node Requirements for SingleStore DB Commands.
  • If the transaction is successful, execute the COMMIT command to commit the changes; if the transaction is unsuccessful or needs to be reverted, then execute the ROLLBACK command to revert the changes.

Example

For this example, consider the following Employee table:

ID Name
30 Jim
20 Rob
40 Rick
BEGIN;
UPDATE Employee SET Name = "John" WHERE ID = 300;
****
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0

Run the SELECT query to verify if the UPDATE is correct:

SELECT * FROM Employee;
****
+------+-------+
| ID   | Name  |
+------+-------+
|   30 | Jim   |
|   20 | Rob   |
|   40 | Rick  |
+------+-------+

Run ROLLBACK since there were no matching results for the ID and the UPDATE was not successful.

ROLLBACK;

Note: Before the user runs COMMIT or ROLLBACK, only that user can see the updates made after BEGIN was run.