Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Rolling Back from Transactions1:15 with Andrew Chalkley
Sometimes errors happen in the middle of a transaction. How do you recover from that? This video shows you how!
To reset the state of the database to before the begining of the transaction:
See all of the SQL used in Modifying Data With SQL in the Modifying Data With SQL Cheatsheet.
Now that you've seen the benefit of using transactions in database save files,
you may be tempted to use them on your own for a series of complex updates.
Now, what happens in the middle of a transaction when you make a typo or
you forget something, and
you just want to get rid of the changes that haven't been committed yet?
This is where the rollback statement comes in.
Let's say you begin your transaction and start inserting rows.
You can even select to see them added, but they're not really added.
No one else can see them if they run the same query.
It's just for you to review.
[SOUND] Then you realize you've done a typo in all of your statements and
you feel like starting over.
That's where rollback comes in.
To undo it, we issue the rollback statement.
When you select from the table now,
the entries you tried to insert aren't there anymore.
That's because they weren't there in the first place.
You didn't commit your changes.
You may have issued multiple code operations in one go.
And issuing them by hand can be problematic.
But rolling back is always an option.
You need to sign up for Treehouse in order to download course files.Sign up