亚洲免费在线视频-亚洲啊v-久久免费精品视频-国产精品va-看片地址-成人在线视频网

您的位置:首頁技術文章
文章詳情頁

sql server 2005中新增加的try catch學習

瀏覽:148日期:2023-10-30 10:45:29

sql server 2005中新增加的try catch,可以很容易捕捉異常了,今天大概學習看了下,歸納下要點如下

基本用法BEGIN TRY {; sql_statement | statement_block; }END TRYBEGIN CATCH {; sql_statement | statement_block }END CATCH,和普通語言的異常處理用法差不多,但要注意的是,SQL SERVER只捕捉那些不是嚴重的異常,當比如數據庫不能連接等這類異常時,是不能捕捉的一個例子:BEGIN TRY DECLARE @X INT -- Divide by zero to generate Error SET @X = 1/0 PRINT 'Command after error in TRY block'END TRYBEGIN CATCH PRINT 'Error Detected'END CATCHPRINT 'Command after TRY/CATCH blocks'; 另外try catch可以嵌套Begin TRY delete from GrandParent where Name = 'John Smith' print 'GrandParent deleted successfully'End TryBegin Catch Print 'Error Deleting GrandParent Record' Begin Try delete from Parent where GrandParentID = (select distinct ID from GrandParent where Name = 'John Smith') Print 'Parent Deleted Successfully' End Try Begin Catch print 'Error Deleting Parent' Begin Try delete from child where ParentId = (select distinct ID from Parent where GrandParentID = (select distinct ID from GrandParent where Name = 'John Smith')) print 'Child Deleted Successfully' End Try Begin Catch Print 'Error Deleting Child' End Catch End CatchEnd Catch另外,SQL SERVER 2005在異常機制中,提供了error類的方法方便調試,現摘抄如下,比較簡單,不予以解釋ERROR_NUMBER(): Returns a number associated with the error.ERROR_SEVERITY(): Returns the severity of the error.ERROR_STATE(): Returns the error state number associated with the error.ERROR_PROCEDURE(): Returns the name of the stored procedure or trigger in which the error occurred.ERROR_LINE(): Returns the line number inside the failing routine that caused the error. ERROR_MESSAGE(): Returns the complete text of the error message. The text includes the values supplied for any substitutable parameters, such as lengths, object names, or times. 最后舉例子如下,使用了error類的方法BEGIN TRY DECLARE @X INT -- Divide by zero to generate Error SET @X = 1/0 PRINT 'Command after error in TRY block'END TRYBEGIN CATCH PRINT 'Error Detected' SELECT ERROR_NUMBER() ERNumber, ERROR_SEVERITY() Error_Severity, ERROR_STATE() Error_State, ERROR_PROCEDURE() Error_Procedure, ERROR_LINE() Error_Line, ERROR_MESSAGE() Error_MessageEND CATCHPRINT 'Command after TRY/CATCH blocks'最后輸出Error DetectedErr_Num Err_Sev Err_State Err_Proc;;Err_Line; Err_Msg------- ------- --------- -------------------- --------- --------------------------------8134;;;;;16; 1 NULL 4;;;;;Divide by zero error encountered.

標簽: Sql Server 數據庫
主站蜘蛛池模板: 在线视频一区二区三区三区不卡 | 国产素人在线观看 | 美女图片131亚洲午夜 | 色久在线 | 亚洲精品午夜一区二区在线观看 | 国产精品视频久久久久 | 中文字幕国产一区 | 国产成a人片在线观看视频 国产成版人视频网站免费下 | 美女视频免费永久观看的 | 国产成人一区二区三区精品久久 | 亚洲天堂色视频 | α片毛片 | 成人免费观看高清在线毛片 | 午夜日韩视频 | 天天综合天天看夜夜添狠狠玩 | 91精品国产爱久久久久 | 亚洲日韩中文字幕 | 亚洲精品国产专区91在线 | 国产a级精品特黄毛片 | 国产毛片一区二区三区精品 | 13一14周岁毛片免费 | 黄色在线播放 | 欧美成人三级网站 | 亚洲国产精品一区二区久久 | 日本韩国一级毛片中文字幕 | 欧做爰xxxⅹ性欧美大 | 国产精品莉莉欧美自在线线 | 欧美一级xxxx俄罗斯一级 | 欧美一级毛片特黄大 | 成年女人色毛片免费 | 亚洲一区在线播放 | 色视频网站大全免费 | 亚洲国产精品日韩在线 | 亚洲一区二区中文 | 国产欧美日韩在线视频 | 秀人网私拍福利视频在线 | 亚洲欧洲日产国产 最新 | 亚洲精国产一区二区三区 | 亚洲综合资源 | 国产日韩精品一区二区 | 综合欧美一区二区三区 |