课程: Program Databases with Transact-SQL
今天就学习课程吧!
今天就开通帐号,24,100 门业界名师课程任您挑!
Capture errors with TRY and CATCH - SQL Server教程
课程: Program Databases with Transact-SQL
Capture errors with TRY and CATCH
- [Instructor] In your SQL server programs, error handling is most often implemented using Try and Catch blocks. The basic syntax is fairly simple. I've got an outline of what that looks like starting on line six and going down to line number 12. At the beginning of the routine, that you want to execute, add BEGIN TRY, then include all of the code you want to run. Assuming that it executes without any problems. After that, you'll have a line that says END TRY followed immediately by a BEGIN CATCH. If any errors are encountered in the TRY block, then the code in the CATCH block is executed. If the TRY block doesn't encounter any errors, then this portion is skipped over, finish the CATCH block with END CATCH . And then you can continue on with other code you want to execute after that. To put this into practice, let's try and execute an insert statement where we don't supply the values that we need for the required fields in a table. I've got that outlined here on line number 18, where…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
-
(已锁定)
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 秒
-
(已锁定)
-
-