Is it possible to rollback a SQL Server transaction without suppressing
the error?
This StackOverflow answer provides an elegant way to use TRY CATCH
ROLLBACK TRANSACTION, but it suppresses the error information.
Is there any way to rollback a transaction that doesn't suppress the error
that resulted in the rollback in the first place?
Here's an example T-SQL script based on the above method:
DECLARE @Table TABLE (
ID INT PRIMARY KEY
)
BEGIN TRY
BEGIN TRANSACTION
INSERT INTO @Table VALUES (1), (1)
COMMIT TRANSACTION
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
ROLLBACK TRANSACTION
END CATCH;
Thanks!
No comments:
Post a Comment