<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      之乎者也,阿彌陀佛

      軟件設(shè)計(jì)的原則就是,化繁為簡,化難為易,把人的思維集中在簡單的領(lǐng)域,然后通過有序的組合實(shí)現(xiàn)復(fù)雜的邏輯。

        博客園  :: 首頁  :: 新隨筆  :: 聯(lián)系 :: 訂閱 訂閱  :: 管理
      oday I am showing you the difference between @@ERROR, BEGIN TRY/CATCH and XACT_ABORT
      The three alternatives to error handling works little different and let us intercept the error handling in different stages in the process.

      First I am going to show you the ordinary @@ERROR check which most of you are used to.
       
      IF OBJECT_ID('uspTest_2000') IS NOT NULL
                 DROP PROCEDURE uspTest_2000
      GO
      CREATE PROCEDURE uspTest_2000
      AS
       
      CREATE TABLE          #Sample
                            (
                                       i TINYINT
                            )
       
      BEGIN TRANSACTION
       
      INSERT     #Sample
      SELECT     209
       
      IF @@ERROR <> 0
                 BEGIN
                            ROLLBACK TRANSACTION
                            PRINT 'Insert Error (User defined error message)'
                 END
      ELSE
                 BEGIN
                            COMMIT TRANSACTION
                            PRINT 'Insert OK (User defined error message)'
                 END
       
      DROP TABLE #Sample
      GO
      DECLARE    @rc INT
       
      SELECT     @rc AS rc,
                 @@TRANCOUNT AS [TransactionCount]
       
      EXEC       @rc = uspTest_2000
       
      SELECT     @rc AS rc,
                 @@TRANCOUNT AS [TransactionCount]
       
      As you can see, the code works ok and no error is generated. You also get two resultsets back with in-going and out-going value for @rc variable.
       
      In SQL Server 2005 BEGIN TRY/CATCH was introduced and can be written like this.
       
      IF OBJECT_ID('uspTest_2005') IS NOT NULL
                 DROP PROCEDURE uspTest_2005
      GO
      CREATE PROCEDURE uspTest_2005
      AS
       
      CREATE TABLE          #Sample
                            (
                                       i TINYINT
                            )
       
      BEGIN TRY
                 BEGIN TRANSACTION
       
                 INSERT     #Sample
                 SELECT     209
       
                 COMMIT TRANSACTION
                 PRINT 'Insert OK (User defined error message)'
      END TRY
       
      BEGIN CATCH
                 ROLLBACK TRANSACTION
                 PRINT 'Insert Error (User defined error message)'
                 PRINT ERROR_MESSAGE()
      END CATCH
       
      DROP TABLE #Sample
      GO
       
      DECLARE    @rc INT
       
      SELECT     @rc AS rc,
                 @@TRANCOUNT AS [TransactionCount]
       
      EXEC       @rc = uspTest_2005
       
      SELECT     @rc AS rc,
                 @@TRANCOUNT AS [TransactionCount]
       
      As you can see, we again get two resultsets back with in-going and out-going values for @rc.
       
      In SQL Server 2005 and SQL Server 2008 we also have the option of  XACT_ABORT.
      You can see here how that is written.
       
      IF OBJECT_ID('uspTest_2008') IS NOT NULL
                 DROP PROCEDURE uspTest_2008
      GO
      CREATE PROCEDURE uspTest_2008
      AS
       
      SET XACT_ABORT ON
       
      CREATE TABLE          #Sample
                            (
                                       i TINYINT
                            )
       
      INSERT     #Sample
      SELECT     209
       
      DROP TABLE #Sample
      GO
      DECLARE    @rc INT
       
      SELECT     @rc AS rc,
                 @@TRANCOUNT AS [TransactionCount]
       
      EXEC       @rc = uspTest_2008
       
      SELECT     @rc AS rc,
                 @@TRANCOUNT AS [TransactionCount]
       
      And again we get two resultset back with in-going and out-going values for @rc.
      So far so good.
      The interesting part begins when error occurs. We can easily produce an error by inserting the value of 2090 instead of 209 in the SMALLINT column. 
       
      IF OBJECT_ID('uspTest_2000') IS NOT NULL
                 DROP PROCEDURE uspTest_2000
      GO
      CREATE PROCEDURE uspTest_2000
      AS
       
      CREATE TABLE          #Sample
                            (
                                       i TINYINT
                            )
       
      BEGIN TRANSACTION
       
      INSERT     #Sample
      SELECT     2090
       
      IF @@ERROR <> 0
                 BEGIN
                            ROLLBACK TRANSACTION
                            PRINT 'Insert Error (User defined error message)'
                 END
      ELSE
                 BEGIN
                            COMMIT TRANSACTION
                            PRINT 'Insert OK (User defined error message)'
                 END
       
      DROP TABLE #Sample
      GO
      DECLARE    @rc INT
       
      SELECT     @rc AS rc,
                 @@TRANCOUNT AS [TransactionCount]
       
      EXEC       @rc = uspTest_2000
       
      SELECT     @rc AS rc,
                 @@TRANCOUNT AS [TransactionCount]
       
      Yes, we do get two resultsets back, and we also get two error messages!
      SQL Server delivers a collection of error messages back to the client! This  collection has two error messages; first one for SQL Server internal and the other is the user defined error message.
       
      Msg 220, Level 16, State 2, Procedure uspTest_2000, Line 11
      Arithmetic overflow error for data type tinyint, value = 2090.
      The statement has been terminated.
      Insert Error (User defined error message)
       
      What happens then with BEGIN TRY/CATCH?
       
      IF OBJECT_ID('uspTest_2005') IS NOT NULL
                 DROP PROCEDURE uspTest_2005
      GO
      CREATE PROCEDURE uspTest_2005
      AS
       
      CREATE TABLE          #Sample
                            (
                                       i TINYINT
                            )
       
      BEGIN TRY
                 BEGIN TRANSACTION
       
                 INSERT     #Sample
                 SELECT     2090
       
                 COMMIT TRANSACTION
                 PRINT 'Insert OK (User defined error message)'
      END TRY
       
      BEGIN CATCH
                 ROLLBACK TRANSACTION
                 PRINT 'Insert Error (User defined error message)'
                 PRINT ERROR_MESSAGE()
      END CATCH
       
      DROP TABLE #Sample
      GO
       
      DECLARE    @rc INT
       
      SELECT     @rc AS rc,
                 @@TRANCOUNT AS [TransactionCount]
       
      EXEC       @rc = uspTest_2005
       
      SELECT     @rc AS rc,
                 @@TRANCOUNT AS [TransactionCount]
       
      The big difference is that now the internal error message provided by SQL Server is not displayed automatically!

      Luckily we also have more error function to use besides the one you see in the code above;  ERROR_MESSAGE.
      One of those is named ERROR_LINE which gives you the line number for the statement generating the error!
      With BEGIN TRY/CATCH we have the option to decide which error message to display and in which order.
       
      Insert Error (User defined error message)
      Arithmetic overflow error for data type tinyint, value = 2090.
       
      How does then XACT_ABORT work? 
       
      IF OBJECT_ID('uspTest_2008') IS NOT NULL
                 DROP PROCEDURE uspTest_2008
      GO
      CREATE PROCEDURE uspTest_2008
      AS
       
      SET XACT_ABORT ON
       
      CREATE TABLE          #Sample
                            (
                                       i TINYINT
                            )
       
      INSERT     #Sample
      SELECT     2090
       
      DROP TABLE #Sample
      GO
      DECLARE    @rc INT
       
      SELECT     @rc AS rc,
                 @@TRANCOUNT AS [TransactionCount]
       
      EXEC       @rc = uspTest_2008
       
      SELECT     @rc AS rc,
                 @@TRANCOUNT AS [TransactionCount]
       
      The big difference is that we don't have to explicit handle our transactions. SQL Server automatically does a rollback.
      The other difference is that all code after the error is skipped.
       
      You can tell due to now there is only one resultset which contains the in-going value for @rc.


      Refer:

      http://weblogs.sqlteam.com/peterl/archive/2009/04/07/ERROR-BEGIN-TRYCATCH-and-XACT_ABORT.aspx

       

      posted on 2012-04-24 13:28  搏擊的小船  閱讀(475)  評論(0)    收藏  舉報(bào)
      主站蜘蛛池模板: 蜜臀av日韩精品一区二区| 免费观看日本污污ww网站69| 亚洲AV成人片不卡无码| 国产精品中文字幕自拍| 人妻中文字幕亚洲一区| 综合在线 亚洲 成人 欧美| 久久精品国产一区二区三区不卡 | 妓女妓女一区二区三区在线观看| 亚洲精品一区二区三区四区乱码| 国产在线拍揄自揄拍无码| 日韩内射美女人妻一区二区三区| 日日猛噜噜狠狠扒开双腿小说 | 内射囯产旡码丰满少妇| 国产男女猛烈无遮挡免费视频| 新版资源天堂中文| 国产三级国产精品国产专| 日韩中文字幕有码av| 日本高清中文字幕免费一区二区| 免费看成人欧美片爱潮app| 国产99在线 | 免费| 又黄又刺激又黄又舒服| 影音先锋男人站| 日本中文一二区有码在线| 狠狠亚洲色一日本高清色| 高清不卡一区二区三区| 日本一区二区三区后入式| 国产a在视频线精品视频下载| 精品视频在线观自拍自拍| 固安县| 国产日韩一区二区在线| 久久成人国产精品免费软件| 国产av普通话对白国语| 久久国产成人精品国产成人亚洲 | 国产精品午夜福利合集| 久青草视频在线免费观看| 日韩伦理片| 亚洲区欧美区综合区自拍区| 德江县| 国产99视频精品免费视频36| 日日碰狠狠躁久久躁96avv| 亚洲精品tv久久久久久久|