CHAPTER 20

image

Error Handling

by David Dye

In this chapter you’ll learn several methods of error handling in T-SQL including structured error handling.

20-1. Handling batch errors

Problem

You have a script containing numerous Data Definition Language(DDL) and Data Manipulation Language(DML) statements that completely fail to run. You need to insure that if part of the script fails due to an error the remaining script will complete, if there are no errors.

Solution

A single script can contain multiple statements and if run as a single batch the entire script will fail. When using SSMS or SQLCMD batches can be separated with the GO command, but ...

Get SQL Server 2012 T-SQL Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.