Control units of work with atomicity.

A sequence of statements treated as a single atomic unit that either all succeed or all fail. Use BEGIN/COMMIT/ROLLBACK to control boundaries. Essential for data integrity in multi-step operations. Keep transactions short to reduce lock contention.

Compatibility

Show:
Database System Support Status Since Version Notes
MySQL ✓ Supported all AUTOCOMMIT=ON by default
PostgreSQL ✓ Supported all Standard
SQL Server ✓ Supported all BEGIN TRAN / COMMIT
Oracle ✓ Supported all AUTOCOMMIT=OFF by default
SQLite ✓ Supported all AUTOCOMMIT=ON by default

Details

Ensure atomic, consistent, isolated, durable operations.

Standard Syntax

BEGIN; UPDATE tbl SET …; INSERT INTO …; COMMIT;

Version Support

MySQL: Since all PostgreSQL: Since all SQL Server: Since all Oracle: Since all SQLite: Since all

Per-Database Syntax & Notes

MySQL

AUTOCOMMIT=ON by default

START TRANSACTION; … COMMIT; -- or ROLLBACK;

PostgreSQL

Standard

BEGIN; … COMMIT; -- or ROLLBACK;

SQL Server

BEGIN TRAN / COMMIT

BEGIN TRANSACTION; … COMMIT TRANSACTION; -- or ROLLBACK TRANSACTION;

Oracle

AUTOCOMMIT=OFF by default

SAVEPOINT sp1; … COMMIT; -- or ROLLBACK TO sp1;

SQLite

AUTOCOMMIT=ON by default

BEGIN; … COMMIT; -- or ROLLBACK;