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, 0:00 you may be tempted to use them on your own for a series of complex updates. 0:04 Now, what happens in the middle of a transaction when you make a typo or 0:09 you forget something, and 0:13 you just want to get rid of the changes that haven't been committed yet? 0:14 This is where the rollback statement comes in. 0:18 Let's say you begin your transaction and start inserting rows. 0:22 You can even select to see them added, but they're not really added. 0:27 No one else can see them if they run the same query. 0:34 It's just for you to review. 0:38 [SOUND] Then you realize you've done a typo in all of your statements and 0:40 you feel like starting over. 0:46 That's where rollback comes in. 0:48 To undo it, we issue the rollback statement. 0:52 When you select from the table now, 0:55 the entries you tried to insert aren't there anymore. 0:57 That's because they weren't there in the first place. 1:00 You didn't commit your changes. 1:03 You may have issued multiple code operations in one go. 1:06 And issuing them by hand can be problematic. 1:09 But rolling back is always an option. 1:12
You need to sign up for Treehouse in order to download course files.Sign up