We can use ROLLBACK command to eliminate the changes, made in a current transaction, permanently from MySQL database. Suppose if we run some DML statements and it updates some data objects, then ROLLBACK command will eliminate these updates permanently from the database.
Example
Suppose we have the following data in table ‘marks’ and we applied the transaction and ROLLBACK command as follows −
mysql> SELECT * FROM Marks; +------+---------+---------+-------+ | Id | Name | Subject | Marks | +------+---------+---------+-------+ | 1 | Aarav | Maths | 50 | | 2 | Harshit | Maths | 55 | +------+---------+---------+-------+ 2 rows in set (0.00 sec) mysql> START TRANSACTION; Query OK, 0 rows affected (0.00 sec) mysql> INSERT INTO Marks Values(3, 'Rahul','History',40); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO Marks Values(4, 'Yashraj','English',48); Query OK, 1 row affected (0.00 sec) mysql> ROLLBACK; Query OK, 0 rows affected (0.04 sec)
In this example, ROLLBACK statement will explicitly end the transaction and changes will be rolled back i.e. eliminated permanently from the database.
mysql> SELECT * FROM Marks; +------+---------+---------+-------+ | Id | Name | Subject | Marks | +------+---------+---------+-------+ | 1 | Aarav | Maths | 50 | | 2 | Harshit | Maths | 55 | +------+---------+---------+-------+ 2 rows in set (0.00 sec)