课程: Program Databases with Transact-SQL
今天就学习课程吧!
今天就开通帐号,24,100 门业界名师课程任您挑!
Generate errors with THROW
- Sometimes SQL server is perfectly happy, executing in instruction that doesn't actually make sense for your specific database. For instance, a user sends a command to perform a task, that's technically valid SQL, but the end result doesn't correspond to the business rules that your organization needs to follow. In these cases, you can create your own custom error messages, using a command called throw. The nice thing about throw is that you can insert it anywhere that you want. It doesn't have to be attached to any actual database or a server errors to see how this can be helpful, I've done a tri catch statement set up here on line seven through 13. The first thing that I'm doing is requesting a row from the people's table. Now this select statement should work just fine and is not going to generate any errors. Then on line number nine, we have our throw command, which will create an error that transfers execution into the catch block. The throw command has three parts to it. First…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
-
(已锁定)
What is error handling?1 分钟 52 秒
-
(已锁定)
Capture errors with TRY and CATCH4 分钟 54 秒
-
(已锁定)
Generate errors with THROW4 分钟 12 秒
-
(已锁定)
Manage transaction control4 分钟 4 秒
-
(已锁定)
Challenge: Add error handling to a stored procedure1 分钟 12 秒
-
(已锁定)
Solution: Add error handling to a stored procedure12 分钟 12 秒
-
(已锁定)
-
-