How To Undo Changes to A Specific Point?
- Turn off the autocommit by type in the following code, and execute it:
SET AUTOCOMMIT = OFF;
This will make all the transactions not to be saved automatically.
- Create a save point by type in the following code, execute it:
COMMIT;
This will create a save point that may be used later.
- Simulate a mistake that we want to rollback later, for example, deleting a table, execute the code:
DELETE FROM employees;
This will delete all the row from the table.
- Undo the mistake using the following code, execute the code:
ROLLBACK;
This will restore current transaction back to the previous save point where we used commit.
- Check the table again:
SELECT * FROM employees;
- If you want to save the current changes:
DELETE FROM employees;
COMMIT;
Execute the code.