Skip to content
Related Articles

Related Articles

Improve Article

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 :

COMMITROLLBACK
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.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :