Welcome to the Treehouse Community
Looking to learn something new?
Siu Chung LEUNG742 Points
If 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?
Steven Parker221,293 Points
The 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 JanekFront End Web Development Techdegree Graduate 30,654 Points
it is a basically a huge UNDO button. Yes you can delete them by selecting and deleting...or just doing this
Nicholas D'AmicoFront End Web Development Techdegree Graduate 25,692 Points
So 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 Younes1,548 Points
Imagine 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.
My 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.