SQL Transactions: COMMIT, ROLLBACK, and SAVEPOINT
By Sharon Ben-Moshe · August 21, 2026 · 2 min read
Sharon Ben-Moshe is the founder of sqlfmt, a browser-based SQL formatter and validator with misspelled-keyword suggestions across PostgreSQL, MySQL, SQLite, SQL Server, and BigQuery.
Use SQL transactions to make related changes together. Learn COMMIT, ROLLBACK, SAVEPOINT, autocommit, and portable safety checks.
Quick answer
A transaction groups related database changes into one unit. COMMIT makes its changes durable; ROLLBACK abandons uncommitted changes; SAVEPOINT creates a named point that can be rolled back to without abandoning all prior work. Autocommit and DDL behavior differ by database.
FAQs
What is the difference between COMMIT and ROLLBACK?
COMMIT makes the current transaction’s changes durable. ROLLBACK abandons uncommitted changes in the transaction, subject to the target database’s statement and transaction rules.
What is a SQL SAVEPOINT?
A SAVEPOINT names a point inside a transaction. Where supported, `ROLLBACK TO SAVEPOINT` can undo work after that point while preserving earlier work in the same transaction.
Does BEGIN work in every database?
Many databases support BEGIN for transactions, but exact syntax, autocommit defaults, and DDL behavior differ. Use the documentation for the database and driver actually running the query.
Should every SELECT use a transaction?
Databases already give individual statements transactional semantics, but longer read workflows may need an explicit transaction for a consistent view. The appropriate isolation level is an application-specific decision.
Keep reading
Building an Enterprise SQL Style Guide: Formatting Standards, Linting, and Team Conventions
By Sharon Ben-Moshe · Oct 13, 2026
The complete blueprint for an enterprise SQL style guide. Standardize formatting, keyword casing, indentation, naming conventions, and CI linting.
Read postThe Master Guide to SQL Common Table Expressions (CTEs): Syntax, Optimization Fences, and Recursion
By Sharon Ben-Moshe · Oct 13, 2026
The definitive guide to SQL Common Table Expressions (CTEs). Master chaining, recursive hierarchies, data-modifying CTEs, and optimization fences.
Read postTry it now
Paste your SQL into sqlfmt — format, validate, and catch typos free in your browser.