In SQL Server, is there something similar to finally clause in try..catch... block of c# ?
I mean, I am using BEGIN TRAN, END TRAN, COMMIT TRAN, ROLLBACK TRAN etc in a SQL Server transaction and want a section or some set of actions that needs to fire irrespective of success or failure or transaction.
Is there a solution for that? (similar to finally block on try/catch of OOPS languages).
Thanks in advance
There is, in fact, a
BEGIN TRY... END TRY...BEGIN CATCH... END CATCHstructure in SQL Server. I use it quite frequently.Here's an overview -- the bit about selecting error information is optional, of course -- do what makes sense in your case.