Reputation: 331
This may be very basic question. If we open a sql transaction with "Begin Transaction", is commit transaction or rollback is mandatory...?
I have a scenario where i need to exit the SP when a row exists in if statement fails. This if statement is currently inside the transaction scope..
Thanks in advance!
Regards Bala
Upvotes: 0
Views: 243
Reputation: 27214
If we open a sql transaction with "Begin Transaction", is commit transaction or rollback is mandatory...?
It's not mandatory, the transaction will stay open until an error or the connection is closed. But you don't want to do this, you may be blocking other users for a very long time.
You should COMMIT TRANSACTION
or ROLLBACK TRANSACTION
at the earliest opportunity.
Upvotes: 1