Last active
May 4, 2018 10:52
-
-
Save umair-me/fd41b19ccbc5407ec63c to your computer and use it in GitHub Desktop.
Run query in transaction with error logs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEGIN TRANSACTION; | |
BEGIN TRY | |
-- ADD SQL QUERIES HERE | |
END TRY | |
BEGIN CATCH | |
SELECT | |
ERROR_NUMBER() AS ErrorNumber | |
,ERROR_SEVERITY() AS ErrorSeverity | |
,ERROR_STATE() AS ErrorState | |
,ERROR_PROCEDURE() AS ErrorProcedure | |
,ERROR_LINE() AS ErrorLine | |
,ERROR_MESSAGE() AS ErrorMessage; | |
IF @@TRANCOUNT > 0 | |
ROLLBACK TRANSACTION; | |
END CATCH; | |
IF @@TRANCOUNT > 0 | |
COMMIT TRANSACTION; | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment