zoukankan      html  css  js  c++  java
  • 事物回滚

    总体作为一个事务,整体提交或整体回滚

    BEGIN tran Price
    DECLARE @tran_error int;
    SET @tran_error=0;
        BEGIN try
        UPDATE t_PortGrant SET PortPrice ='200' WHERE StageID=73 AND StaffID='18440' and BasePID='1501'
        set @tran_error=@tran_error+@@error;
        update t_BaseProduct SET ImagePrice='200' where StageID=73 and BasePID='1544401'
        set @tran_error=@tran_error+@@error;
        end try
    BEGIN CATCH
        PRINT '出现异常,错误编号:' + convert(varchar,error_number()) + ',错误消息:' + error_message()
        SET @tran_error = @tran_error + 1
    END CATCH


    IF(@tran_error > 0)
        BEGIN
            --执行出错,回滚事务
            ROLLBACK TRAN;
            PRINT '价格修改失败!';
        END
    ELSE
        BEGIN
            --没有异常,提交事务
            COMMIT TRAN;
            PRINT '价格修改成功!';
        END

    SET XACT_ABORT ON
    BEGIN TRAN
    --要执行的语句
    UPDATE t_PortGrant SET PortPrice='200' WHERE StageID='73' AND StaffID='18440' AND BasePID=1501
    UPDATE t_BaseProduct SET ImagePrice='200' WHERE StageID='73' AND BasePID='1234'
    COMMIT TRAN
    GO

    其中某一条SQL语句执行出错时,则事物回滚,两天语句都不会执行操作

  • 相关阅读:
    Git
    Qcon2016上海站PPT
    TeamCity
    在cmd界面,怎么样退出Node.js运行环境
    python 2.x与python3.x的区别
    d3.max()与d3.min()
    d3.svg.line() 曲线构造器
    d3.js 之SVG:矢量化图形绘制
    moment.js 时间格式化库
    directive
  • 原文地址:https://www.cnblogs.com/starts/p/5160900.html
Copyright © 2011-2022 走看看