Go Back

ROLLBACK: Undo changes made in a transaction in sql

3/5/2024
All Articles

ROLLBACK: Undo changes made in a transaction in sql

 ROLLBACK: Undo changes made in a transaction in sql

 ROLLBACK in Sql

In SQL, the ROLLBACK statement is used to undo transactions that have not been permanently saved to the database.
 It is typically used in conjunction with the BEGIN TRANSACTION and COMMIT statements to manage transactions.

 

 BEGIN TRANSACTION;

-- DDL, INSERT, UPDATE, DELETE

-- If something goes wrong, you can rollback the transaction
ROLLBACK;

-- If everything is successful, you can commit the transaction make it as done
-- COMMIT;

 

Any modifications performed during the current transaction are reversed and the database is returned to its initial state when a ROLLBACK statement is executed. It is vital to remember that ROLLBACK does not reverse changes made by previously committed transactions; it only affects the current transaction.

 

Article