Begin, Commit, Rollback
In SQL database management systems, BEGIN, COMMIT, and ROLLBACK are the most commonly used SQL database table transaction control command statements. The BEGIN, COMMIT, and ROLLBACK commands in SQL are used to manage and control user-defined database table data transactions.
These commands help you apply user-defined custom changes and updates to existing database tables. These database commands help maintain the accuracy, integrity, and reliability of data by controlling the database.

These SQL commands are commonly used in banking systems, payment gateway applications, and other secure database transaction applications where the database user must handle or manage data table transactions in a secure order.
BEGIN SQL Database Command.
The BEGIN command in SQL database tables is used to start a new database transaction. The BEGIN command represents the starting state of a group of SQL data operations, which can be committed or rolled back together if necessary.
Example of the BEGIN SQL command.
BEGIN;
UPDATE UserAccounts
SET Balance = Balance – 9872
WHERE AccountID = 343;
Here, the BEGIN command statement starts a new transaction, deducting or withdrawing ₹9872 from the user’s customer bank account 343. The subsequent user account change modifications have not yet been committed.
More importantly, remember that the BEGIN command in a database table starts a new database table transaction.
COMMIT SQL Database Command.
The COMMIT command in a SQL database table is used to permanently save or store all custom database user modification updates made during the current database table transaction. Once a transaction is committed for a custom update modification by a database user, all user modifications to the existing database table are fixed or permanent, as per the transaction guarantees.
COMMIT SQL Command example.
BEGIN;
UPDATE UserAccounts
SET Balance = Balance – 13909
WHERE AccountID = 3423;
UPDATE UserAccounts
SET Balance = Balance + 13909
WHERE AccountID = 3427;
COMMIT;
Here in the COMMIT SQL Database Command.
- In this example, ₹13909 is deducted or withdrawn from user customer account 3423.
- ₹13909 is added or deposited to the same user customer account 3427.
- The COMMIT command here saves all user modification updates to both user and customer tables.
More importantly, remember that the COMMIT command permanently saves or stores user transaction modifications in the database table.
ROLLBACK SQL Database Command.
The ROLLBACK command statement in a SQL database table is used to cancel, reject, or discard all updates or modifications to the user account table made during an existing uncommitted database table transaction.
The ROLLBACK command statement restores the database to the condition or state before the transaction began. This depends entirely on the transaction behavior of your existing database tables.
Example of the ROLLBACK SQL Command.
BEGIN;
UPDATE UserAccounts
SET Balance = Balance – 4343
WHERE AccountID = 999;
ROLLBACK;
Here in the ROLLBACK SQL Database Command.
- It starts a database table transaction.
- Within the transaction, ₹4343 is deducted or withdrawn from account 999 in the existing database table.
- At the same time, the ROLLBACK database table command cancels or rejects all user modification updates.
- The withdrawn user customer bank balance is then restored to its original bank account balance.
More importantly, remember that the uncommitted database transaction in the ROLLBACK command statement cancels or rejects the user modification.
Main Difference Between BEGIN, COMMIT, and ROLLBACK Command
| # | Command | Purpose of Command | Each Command Output |
| 1. | BEGIN | Begin command starts a new database transaction | It used to begin a new fresh database table transaction |
| 2. | COMMIT | Commit command saves database transaction changes | It used to save change become permanent in secondary storage |
| 3. | ROLLBACK | Rollback command helps us to cancels transaction changes | It is used to uncommitted changes are undone cancel or reject |
Real-life example of a customer user bank account transfer.
Suppose customer account X in a bank has ₹17,000, and the same customer account Y has a deposit of ₹9,000. Here, we want to transfer ₹5,000 from bank account X to account Y.
Customer bank account transfer SQL program.
BEGIN;
UPDATE UserAccounts
SET Balance = Balance – 5000
WHERE AccountID = 999;
UPDATE UserAccounts
SET Balance = Balance + 5000
WHERE AccountID = 1111;
COMMIT;
Customer X Account to Y Successful Amount Execution.
| # | Bank Account | Before Amount Transfer | After Amount Transfer |
| 1. | Bank Customer Account X | ₹ 17,000 | ₹12000 |
| 2. | Bank Customer Account Y | ₹9000 | ₹14000 |
If an error is displayed before the COMMIT command, we can execute it.
ROLLBACK;
It cancels or rejects uncommitted user modification updates to your existing database tables and restores the original account balances to the same account location.
Benefits of the BEGIN, COMMIT, and ROLLBACK transaction control commands in SQL databases.
- They maintain the consistency of your existing database table’s digital data and information.
- They stop incomplete table transactions from being used or applied to the database.
- They help recover from any table transaction errors in the database.
- They support reliable financial data operations in your existing database.
- They help database users avoid unwanted user modifications to database table data.
- They help implement the ACID atomicity property in SQL database tables.
Conclusion of Begin, Commit, Rollback.
In SQL database management systems, the BEGIN, COMMIT, and ROLLBACK commands are essential database table SQL transaction control command statements. The BEGIN command starts a new transaction in your database table, the COMMIT command permanently saves user modifications to an existing database table or stores them in secondary storage, and the ROLLBACK command cancels or rejects any uncommitted user modification changes to your database.
The BEGIN, COMMIT, and ROLLBACK commands in SQL databases help maintain the integrity of your existing database, prevent incomplete database table operations, and ensure accurate, reliable data transaction processing.
Finally, BEGIN, COMMIT, and ROLLBACK in SQL databases provide powerful database user modification update transaction management, and play a key role in enforcing ACID properties in your database table system.
