How To Undo Changes to A Specific Point?

  1. 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.
  2. Create a save point by type in the following code, execute it:
    COMMIT;
    This will create a save point that may be used later.
  3. 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.
  4. 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.
  5. Check the table again:
    SELECT * FROM employees;
  6. If you want to save the current changes:
    DELETE FROM employees;
    COMMIT;
    Execute the code.