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 trial

Databases Modifying Data with SQL Handling Errors When Manipulating Data Rolling Back from Transactions

Siu Chung LEUNG
Siu Chung LEUNG
742 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?

5 Answers

Steven Parker
Steven Parker
229,744 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.

Nicholas D'Amico
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Nicholas D'Amico
Front 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 Younes
Rami Younes
1,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.

Steven Parker
Steven Parker
229,744 Points

OR, if it's not quite right, you might want to make another change (or a few) and then COMMIT.