zoukankan      html  css  js  c++  java
  • 存储过程事务

    BEGIN TRY --开始捕捉异常
    BEGIN TRANSACTION --开始 事务
    insert into DictInfoes values(' 1111',0) --插入数据
    select 1/0
    --除0
    insert into DictInfoes values(' 1111',0) --插入数据
    COMOKIT -- 提交事务
    ENDTRY-结束捕捉异常
    BEGIN CATCH
    --开始处理异常

    IF @@TRANCOUNT > 0 -- 判断是否发生事务
    R0LLBACK -- 回滚
    DECLARE @ErrMsg nvarchar (4000),@ErrSeverity int --定义变里
    SELECT @ErrMsg = ERROR_ _MESSAGE(),
    @ErrSeverity = ERROR_ SEVERITY() -- 查询错误信息
    RAISERROR (@ErrMsg,@ErrSeverity, 1) -- 抛出错误信息
    END CATCH
    --结束处理异常

    -------------------------

    勿悔 20:29:26
    现在方便就发来吧

    黄晨旭15093312145 20:29:38
    create proc DelStudent(@Sid int,@msg int out)
    as
    begin
    begin try
    begin tran       --开始事务
    declare @ClassId int
            select @ClassId = ClassId from Student where Sid = @Sid
            delete from Student where Sid = @Sid
            update Class set StuCount = StuCount - 1 where Cid = @ClassId
            set @msg = 1
    commit             --提交事务
    end try
    begin catch
    rollback tran      --回滚事务
    set @msg = 0
    end catch
    end

  • 相关阅读:
    Django + uWSGI + Nginx 实现生产环境部署
    面试题(一)
    Python基础之路
    Tornado之实例和扩展
    Scrapy源码研究前戏
    算法之基本概念
    RedHat6.2系统安装ipvsadm+keepalived
    oracle11G 同时支持IPV4和IPV6配置
    redhat6.5 安装oracle11G
    python解析字体反爬
  • 原文地址:https://www.cnblogs.com/gc1229/p/13269118.html
Copyright © 2011-2022 走看看