Created
December 10, 2015 14:01
-
-
Save lookitstony/5e0a80446b59e45f97f6 to your computer and use it in GitHub Desktop.
Basic try catch setup for sql scripts
This file contains hidden or 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 tran | |
| begin try | |
| -- sql code | |
| commit tran | |
| end try | |
| begin catch | |
| rollback tran | |
| declare @errorMessage nvarchar(4000) = error_message() | |
| declare @errorSeverity int = error_severity() | |
| declare @errorState int = error_state() | |
| raiserror(@errorMessage, @errorSeverity, @errorState) | |
| end catch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment