Skip to content
Related Articles

Related Articles

Difference between COMMIT and ROLLBACK in SQL
  • Difficulty Level : Basic
  • Last Updated : 07 Apr, 2020

1. COMMIT :
COMMIT in SQL is a transaction control language which is used to permanently save the changes done in the transaction in tables/databases. The database cannot regain its previous state after the execution of it.

Consider the following STAFF table with records:

STAFF

Example:



sql> 
SELECT *
FROM Staff
WHERE Allowance = 400;

sql> COMMIT; 

Output:

So, the SELECT statement produced the output consisting of three rows.

2. ROLLBACK :
ROLLBACK in SQL is a transactional control language which is used to undo the transactions that have not been saved in database. The command is only be used to undo changes since the last COMMIT.

Consider the following STAFF table with records:

STAFF

Example:



sql> 
SELECT *
FROM EMPLOYEES
WHERE ALLOWANCE = 400;

sql> ROLLBACK; 

Output:

So, the SELECT statement produced the same output with ROLLBACK command.

Difference between COMMIT and ROLLBACK :

COMMIT ROLLBACK
COMMIT permanently saves the changes made by current transaction. ROLLBACK undo the changes made by current transaction.
Transaction can not undo changes after COMMIT execution. Transaction reaches its previous state after ROLLBACK.
When transaction is successful, COMMIT is applied. When transaction is aborted, ROLLBACK occurs.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :