SQL Transaction Commit, Autocommit & Rollback.
SQL Transaction Commit, Autocommit & Rollback.
What is a Transaction?
It ensures that either all the operations succeed (commit) or none take effect (rollback).
The COMMIT command saves all the changes made during the current transaction permanently.
Example:
START TRANSACTION;
Key Points:
- Once a COMMIT is executed, changes are permanent and visible to other users.
Some databases (like MySQL) operate in AUTOCOMMIT mode by default, meaning every SQL
statement is treated as
Page 1
Example:
Key Points:
The ROLLBACK command undoes changes made in the current transaction if something goes
wrong.
Example:
START TRANSACTION;
Key Points:
Page 2
1. Use transactions when performing multiple related operations to ensure consistency.
4. For databases in AUTOCOMMIT mode, explicitly use START TRANSACTION for grouped
operations.
Page 3