Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSiu Chung LEUNG
742 PointsIf begin; is used, why would you need a rollback function when your command is not yet committed?
If begin; is used, why would you need a rollback function when your command is not yet committed? Why don't we just delete the previous statement?
5 Answers
Steven Parker
231,184 PointsThe rollback is for you, commit is for everyone else.
Even if you haven't performed a commit, you will still see any changes your code has made to the data until you perform the rollback. That puts your view of the data back in sync with the permanent copy that anyone else would see. If you do a commit instead, it puts the permanent data in sync with your temporary view.
But until you do one or the other, your view is out of sync with the permanent data.
Michal Janek
Front End Web Development Techdegree Graduate 30,654 Pointsit is a basically a huge UNDO button. Yes you can delete them by selecting and deleting...or just doing this
Nicholas D'Amico
Front End Web Development Techdegree Graduate 25,692 PointsSo the keyword 'rollback' is not useful in a script file when seeding data, but when you are entering rows into the database manually through the terminal or something similar?
Rami Younes
1,548 PointsImagine you're working in a group or in a company. The BEGIN......COMMIT is a good way to check your work before actually comitting it for the whole group/company to see. If you find a mistake you can use the ROLLBACK keyword to undo your work.
Vanessa Schwegman
3,587 PointsMy understanding is that isn't good to leave uncommitted transactions open in a database? As already mentioned, you'd want your view of the database to reflect the reality of the data in it so you'd want to rollback uncommitted changes regardless.
Steven Parker
231,184 PointsOR, if it's not quite right, you might want to make another change (or a few) and then COMMIT.