Question

I'm using sql transactions as containers for APPLOCKS and other concurrency mechanisms and so I sometimes create transactions at various isolation levels which only read data and don't write. I believe that in these situations, logically, COMMIT and ROLLBACK have identical outcomes.

For performance reasons, I'd like to know which one is cheaper/quicker for the server to execute? Is unavoidable bookkeeping required that is optimized for the COMMIT case and additional overhead for ROLLBACK even if there are no writes? Locks will be released in either case.

If it doesn't matter, then I don't have to litter my .NET TransactionScope code with an unnecessary scope.Complete() which might make me hesitate when reviewing code of an otherwise-obviously-read-only operation.

Thanks!

Was it helpful?

Solution

As you are not writing anything, you should go for Commit as it in addition to closing the transaction it also releases any locks you may have had. Though technically Rollback will also do the same, but Commit is always faster then rollback.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top