// dialect comparison

Turning autocommit on or off in every SQL dialect

Autocommit on means every statement is its own transaction. Turning it off groups statements until you COMMIT.

Filed under Sessions & admin

The verdict

Only MySQL and the client libraries have a real toggle. The pattern is inverted across engines: PostgreSQL and SQLite autocommit unless you say BEGIN; Oracle never autocommits unless the driver does; SQL Server has a mode that stops autocommitting indirectly.

Where they differ

MySQL has a real autocommit variable. The others either never autocommit (Oracle), always autocommit without a server toggle (PostgreSQL, SQLite), or simulate it with implicit transactions (SQL Server).

How each engine writes it

SQL Server

SET IMPLICIT_TRANSACTIONS ON;
-- a transaction opens implicitly at the next DML; COMMIT or ROLLBACK closes it
SET IMPLICIT_TRANSACTIONS OFF;

No direct autocommit off switch; implicit transactions is the inverse mode. @@TRANCOUNT tells you whether one is open.

PostgreSQL

-- no toggle: each statement autocommits; wrap multi-statement work in BEGIN/COMMIT

Statements outside an explicit transaction each commit themselves, and BEGIN is the only way to group them. psql's \set AUTOCOMMIT off and drivers such as psycopg emulate a toggle by sending BEGIN for you.

MySQL

SET autocommit = 0;
-- statements now join an implicit transaction until COMMIT or ROLLBACK
SET autocommit = 1;

SET autocommit = 0 (or 1 to restore) applies to the session; SET GLOBAL autocommit changes the server default. START TRANSACTION suspends autocommit until that transaction ends.

SQLite

-- no toggle: autocommit is always on unless an explicit BEGIN is open

Every statement outside BEGIN/COMMIT autocommits. sqlite3_get_autocommit() reports the state; drivers like Python's sqlite3 emulate a toggle in the client.

Oracle

-- the database never autocommits: every DML needs an explicit COMMIT
UPDATE accounts SET balance = 0 WHERE id = 1;
COMMIT;

SQL*Plus SET AUTOCOMMIT ON and JDBC (autocommit on by default) commit from the client; the server never does. DDL issues an implicit COMMIT before and after.

Questions that come up

Why did my MySQL session lose autocommit = 0?

It is session-scoped and resets on reconnect. Connection pools often reset session variables; set it per transaction with START TRANSACTION instead.

Is autocommit bad?

Not for single-statement writes. It becomes a bug when application logic assumes multi-statement atomicity without an explicit transaction; then autocommit silently converts one failure into a partial state.

What does the driver's autocommit flag do?

JDBC, ADO.NET and friends manage it in the client: they issue BEGIN/COMMIT for you. That works uniformly, which is why most ORMs expose autocommit and leave server variables alone.

Keep reading

// write it once, run it anywhere

Switch engines without relearning SQL

SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.