Skip to content

Instantly share code, notes, and snippets.

@lookitstony
Created December 10, 2015 14:01
Show Gist options
  • Select an option

  • Save lookitstony/5e0a80446b59e45f97f6 to your computer and use it in GitHub Desktop.

Select an option

Save lookitstony/5e0a80446b59e45f97f6 to your computer and use it in GitHub Desktop.
Basic try catch setup for sql scripts
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