Reputation: 319
I'm working on SQL Server 2005 and I see that until the Transaction is not committed the changes made are not visible in the database. My question is that If the changes are not done until commit is executed then why do we rollback the transaction if any error occurs in between the Transaction ??? Even if I don't rollback the transaction i still see the same state of the database as it was before the start of the Transaction so what's the point of rolling back a transaction then ?
Upvotes: 1
Views: 700
Reputation: 547
Taken from this answer:
If you neither commit nor rollback the transaction, the transaction will continue to exist indefinitely.
And from microsoft docs:
You can use ROLLBACK TRANSACTION to erase all data modifications made from the start of the transaction or to a savepoint. It also frees resources held by the transaction.
Upvotes: 2
Reputation: 1830
You must rollback so that the server knows you are done with the current transaction. If you don't, all future changes are never writte to the DB.
Upvotes: 2