zoukankan      html  css  js  c++  java
  • SQL Server 事务处理 回滚事务

    创建表:

    复制代码
    SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATETABLE[dbo].[t1](     [Id][int]NOTNULL,     [c1][nvarchar](50) NULL,     [c2][datetime]NULL, CONSTRAINT[PK_Table1]PRIMARYKEYCLUSTERED (     [Id]ASC )WITH (PAD_INDEX  =OFF, STATISTICS_NORECOMPUTE  =OFF, IGNORE_DUP_KEY =OFF, ALLOW_ROW_LOCKS  =ON, ALLOW_PAGE_LOCKS  =ON) ON[PRIMARY] ) ON[PRIMARY]
    复制代码

    解决方案(一)

    复制代码
    declare   @iErrorCount   intset@iErrorCount=0begintran Tran_2008_10_07
    insertinto t1(Id, c1) values(1,'1') set@iErrorCount=@iErrorCount+@@error
    insertinto t1(Id, c1) values(2,'2') set@iErrorCount=@iErrorCount+@@error
    insertinto t1(Id, c1) values('xxxx3','3') set@iErrorCount=@iErrorCount+@@error
    insertinto t1(Id, c1) values(4,'4') set@iErrorCount=@iErrorCount+@@error
    insertinto t1(Id, c1) values(5,'5') set@iErrorCount=@iErrorCount+@@error
    if@iErrorCount=0   begin       COMMITTRAN Tran_2008_10_07   endelse     begin       ROLLBACKTRAN Tran_2008_10_07   end
    复制代码

    解决方案(二)

    复制代码
    begin try     begintran Tran_2008_10_07
           
    insertinto t1(Id, c1) values(1,'1')
           
    insertinto t1(Id, c1) values(2,'2')
           
    insertinto t1(Id, c1) values('xxxx3','3')
           
    insertinto t1(Id, c1) values(4,'4')
           
    insertinto t1(Id, c1) values(5,'5')
       
    COMMITTRAN Tran_2008_10_07 end try begin catch     raiserror 50005N'出错了'     ROLLBACKTRAN Tran_2008_10_07 end catch
    复制代码

    http://www.cnblogs.com/emanlee/archive/2008/10/07/1305424.html

  • 相关阅读:
    MySQL 日志管理
    nginx 日志分割
    Canvas 动态小球重叠效果
    Canvas制作动态进度加载水球
    js 多张爆炸效果轮播图
    js 多张图片加载 环形进度条
    INSTALL_FAILED_CONFLICTING_PROVIDER
    安卓 文件管理器 各种应用 源码
    android 静音
    android studio 查看大纲
  • 原文地址:https://www.cnblogs.com/cmblogs/p/3414439.html
Copyright © 2011-2022 走看看