Skip to content

ROLLBACK

START TRANSACTION;
UPDATE Employees SET salary = salary + 100 WHERE employee_id = 1;
ROLLBACK;
SELECT * FROM Employees WHERE employee_id = 1;
+-------------+-------+--------+
| employee_id | name | salary |
+-------------+-------+--------+
| 1 | John | 5000 |
+-------------+-------+--------+

In the example, initially a transaction is started with the START TRANSACTION statement. An UPDATE statement is issued to increase the salary of an employee with the employee id of 1 by 100. However, the ROLLBACK statement is called immediately after which undoes the changes made by the UPDATE statement. Therefore, when the data is fetched, the salary of the employee with the id of 1 remains as it was prior to the UPDATE, hence displaying its original value.