From the course: Designing Database Solutions for SQL Server 2016

Unlock the full course today

Join today to access over 23,300 courses taught by industry experts.

Error handling in stored procedures

Error handling in stored procedures

- [Instructor] When designing stored procedures in SQL Server it's important to think through all of the ways that a user can misuse the objects that you create. By anticipating common errors and implementing programmatic responses you can create a better experience and help the database walk users through some troubleshooting steps instead of exposing them to potentially confusing error messages. So let's go ahead and try building a stored procedure that uses a couple of error handling techniques, and we'll do that inside of a new database that I'll call error handling DB. First we'll set this up by creating a table called products. The products table is going to have a column for product ID, product name, and expiration date. The product ID is going to be the primary key for the table which means that it won't allow duplicate values and the expiration date is going to have a check constraint applied to it and we're not going to allow any expiration dates that are before January 1st,…

Contents