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
SQL BETWEEN Is Inclusive: Safer Date Range Queries
By Sharon Ben-Moshe · Aug 21, 2026
SQL BETWEEN includes both endpoints. Learn the timestamp boundary trap and use half-open date ranges that stay correct across databases.
Read postSQL DELETE vs TRUNCATE vs DROP: Choose Safely
By Sharon Ben-Moshe · Aug 21, 2026
DELETE removes selected rows, TRUNCATE empties a table, and DROP removes the table itself. Learn the crucial differences before running destructive SQL.
Read postTry it now
Paste your SQL into sqlfmt — format, validate, and catch typos free in your browser.