SQL ROLLBACK command

The rollback command in SQL is used to restore the database to the last commited state. The ‘rollback command can also be used with ‘savepoint’ command to jump to a savepoint in a running transaction.

 

ROLLBACK command

Take for instance, if you use the update command to make some changes in the database, and then realized that those changes were not required, you can use the ‘rollback’ command to rollback those changes, if they were not committed using the commit command. This can be done with the syntax shown below;

Syntax,

ROLLBACK TO savepoint_name;

 

SAVEPOINT command

In SQL the ‘savepoint’ command can be used to temporarily save a transaction so you can rollback to a required point at any time.

This can be done with the syntax shown below;

SAVEPOINT savepoint_name;

Additionally, with this command, you can ‘name’ the different states of your data in any table and then rollback to that state using the rollback command where needed.