Skip to main content

SET AUTOCOMMIT (bSQL) | Blockpoint Docs

Sets the AUTOCOMMIT variable for the current transaction, dictating all subsequent mutations as atomic (set true) or non-atomic (set false). The default value is true for any batched transaction.

bSQL Syntax Conventions

Syntax​

SET AUTOCOMMIT = <boolean>

<boolean> ::=
{ 0 | 1 | TRUE | FALSE }

Arguments​

boolean
The value to set AUTOCOMMIT to.

Examples​

A. Committing a non-atomic transaction.​

The AUTOCOMMIT statement is used in conjunction with a START TRANSACTION statement. The first insertions is done atomically and is automatically committed to the database because AUTOCOMMIT defaults to true. Because we set AUTOCOMMIT to false, the second insertion isn't committed until the final COMMIT statement.

This example uses the Financial Demo Database.

START TRANSACTION
INSERT financial.companies VALUES
("MYL", "Mylan", "Health Care")
SET AUTOCOMMIT = 0
INSERT financial.companies VALUES 
("POLA", "Polar Power, Inc", "Industrial")
COMMIT

B. Using auto commit to rollback a transaction.​

If we were to instead ROLLBACK this transaction at the end and execute the following query, we would only undo the uncommitted statement, in this case the second insertion hasn't been committed when ROLLBACK is run.

START TRANSACTION
INSERT financial.companies VALUES 
("MYL", "Mylan", "Health Care")
SET AUTOCOMMIT = 0
INSERT financial.companies VALUES 
("POLA", "Polar Power, Inc", "Industrial")
ROLLBACK 

See Also​