From the course: Microsoft SQL Server 2016: Query Data

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Error handling

Error handling - SQL Server Tutorial

From the course: Microsoft SQL Server 2016: Query Data

Start my 1-month free trial

Error handling

- [Instructor] In this lesson, we'll take a look at error handling in your Transact-SQL code. Errors, which we never create intentionally, do creep into our code from time to time. SQL Server provides us with the ability to use structured error handling in our T-SQL scripts that can help catch and handle errors that come up during execution. Structured error handling allows for changing the flow of code in response to error conditions. Structured exception handling is the preferred method of error checking in T-SQL code, because it provides a more robust method of error checking and handling. In order to do so, you use TRY/CATCH blocks to wrap blocks of code, and these are known as protected blocks, and this is done to provide error handling for that specific set of Transact-SQL statements. T-SQL does not support the use of FINALLY, as found in some programming language exception handling mechanisms. TRY/CATCH will catch errors having severity higher than 10 and those that do not…

Contents