2 Day Developer > Using SQL > Using Transaction Control S... > Rolling Back a Transaction
Rolling Back a Transaction |
![]() Previous |
![]() Next |
You can use the SQL ROLLBACK statement to rollback (undo) any changes you made to the database before a COMMIT was issued.
Example: Using the SQL ROLLBACK Statement to Undo Changes shows how to use ROLLBACK to rollback the deletions made to the employees table. Note that the ROLLBACK was issued before a COMMIT was issued.
|
Note: If you are using SQL Commands, disable the Autocommit feature when trying this example. |
Using the SQL ROLLBACK Statement to Undo Changes
-- delete a row (record)
DELETE FROM employees WHERE last_name = 'Doe';
-- rollback the delete statement because the previous DELETE was incorrect
ROLLBACK;
-- the following is valid
SELECT * FROM employees WHERE last_name = 'Doe';