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

ROLLBACK before or after switching Autocommit on?

I have one concern. As we see in this video, ROLLBACK is used in a transaction. (BEGIN ... ROLLBACK ... COMMIT). What happen if we create a transaction then ROLLBACK that transaction. Is it possible to undo that transaction? Ex: BEGIN; .... COMMIT; ROLLBACK;

1 Answer

Chris Jones
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Jones
Java Web Development Techdegree Graduate 23,933 Points

Hi hahy,

Once you've committed the transaction, you can't roll it back. Here is some documentation on that from Microsoft's T-SQL.

However, based on the documentation below it sounds like there are some exceptions to that general rule, like a commitment is nested is nested inside a larger transaction and the larger transaction is rolled back.

"A transaction cannot be rolled back after a COMMIT TRANSACTION statement is executed, except when the COMMIT TRANSACTION is associated with a nested transaction that is contained within the transaction being rolled back. In this instance, the nested transaction will also be rolled back, even if you have issued a COMMIT TRANSACTION for it."

https://docs.microsoft.com/en-us/sql/t-sql/language-elements/rollback-transaction-transact-sql

Hope that helps! Let me know if you have any more questions!