Have I to count transactions before rollback one in catch block in T-SQL?
- by abatishchev
I have next block in the end of each my stored procedure for SQL Server 2008
BEGIN TRY
BEGIN TRAN
-- my code
COMMIT
END TRY
BEGIN CATCH
IF (@@trancount > 0)
BEGIN
ROLLBACK
DECLARE @message NVARCHAR(MAX)
DECLARE @state INT
SELECT @message = ERROR_MESSAGE(), @state = ERROR_STATE()
RAISERROR (@message, 11, @state)
END
END CATCH
Is it possible to switch CATCH-block to
BEGIN CATCH
ROLLBACK
DECLARE @message NVARCHAR(MAX)
DECLARE @state INT
SELECT @message = ERROR_MESSAGE(), @state = ERROR_STATE()
RAISERROR (@message, 11, @state)
END CATCH
or just
BEGIN CATCH
ROLLBACK
END CATCH
?