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
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | Native | all | AUTOCOMMIT=ON by default |
| PostgreSQL | Native | all | Standard |
| SQL Server | Native | all | BEGIN TRAN / COMMIT |
| Oracle | Native | all | AUTOCOMMIT=OFF by default |
| SQLite | Native | all | AUTOCOMMIT=ON by default |
Details
Ensure atomic, consistent, isolated, durable operations.
Standard Syntax
BEGIN;
UPDATE tbl SET …;
INSERT INTO …;
COMMIT;
Version Support
MySQL: Native in all listed versions
PostgreSQL: Native in all listed versions
SQL Server: Native in all listed versions
Oracle: Native in all listed versions
SQLite: Native in all listed versions
Per-Database Syntax & Notes
MySQL Native syntax
AUTOCOMMIT=ON by default
START TRANSACTION;
…
COMMIT;
-- or ROLLBACK;
PostgreSQL Native syntax
Standard
BEGIN;
…
COMMIT;
-- or ROLLBACK;
SQL Server Native syntax
BEGIN TRAN / COMMIT
BEGIN TRANSACTION;
…
COMMIT TRANSACTION;
-- or ROLLBACK TRANSACTION;
Oracle Native syntax
AUTOCOMMIT=OFF by default
SAVEPOINT sp1;
…
COMMIT;
-- or ROLLBACK TO sp1;
SQLite Native syntax
AUTOCOMMIT=ON by default
BEGIN;
…
COMMIT;
-- or ROLLBACK;