zoukankan      html  css  js  c++  java
  • 用 @@ERROR 检测几条语句的成功

    用 @@ERROR 检测几条语句的成功

    下面的示例取决于 INSERT 和 DELETE 语句的成功操作。局部变量在两条语句后均被设置为 @@ERROR 的值,并且用于此操作的共享错误处理例程中。

    USE pubs
    GO
    DECLARE @del_error int, @ins_error int
    -- Start a transaction.
    BEGIN TRAN
    -- Execute the DELETE statement.
    DELETE authors
    WHERE au_id = '409-56-7088'
    -- Set a variable to the error value for
    -- the DELETE statement.
    SELECT @del_error = @@ERROR
    -- Execute the INSERT statement.
    INSERT authors
    VALUES('409-56-7008', 'Bennet', 'Abraham', '415 658-9932',
    '6223 Bateman St.', 'Berkeley', 'CA', '94705', 1)
    -- Set a variable to the error value for
    -- the INSERT statement.
    SELECT @ins_error = @@ERROR
    -- Test the error values.
    IF @del_error = 0 AND @ins_error = 0
    BEGIN
    -- Success. Commit the transaction.
    PRINT "The author information has been replaced"
    COMMIT TRAN
    END
    ELSE
    BEGIN
    -- An error occurred. Indicate which operation(s) failed
    -- and roll back the transaction.
    IF @del_error <> 0
    PRINT "An error occurred during execution of the DELETE
    statement."
    IF @ins_error <> 0
    PRINT "An error occurred during execution of the INSERT
    statement."
    ROLLBACK TRAN
    END
    GO
    
  • 相关阅读:
    Java中的事务
    ABCDE
    Android 防内存泄露handler
    自建应用新花样,菜鸟也会做应用
    软件測试之独步武林系列(一)
    刚在在win8.1下装了ubuntu12.04
    SVN 的一些操作
    [华为机试练习题]42.求二叉树的深度和宽度
    iOS_正則表達式
    在应用中更新App版本号
  • 原文地址:https://www.cnblogs.com/zhuawang/p/809400.html
Copyright © 2011-2022 走看看