begin tran
insert into a values(1,11,111)
if @@error <> 0  then goto Err
insert into a values(2,11,111)
if @@error <> 0  then goto Err
insert into a values(3,11,111)
if @@error <> 0  then goto Err
insert into a values(4,18,111)
if @@error <> 0  then goto Err
insert into a values(7,81,111)
if @@error <> 0  then goto Err
commit
return
Err:
      rollback

解决方案 »

  1.   

    begin transaction a
    SET NOCOUNT ON
    SET XACT_ABORT ON
    create table a(
    i tinyint,
    ii smallint,
    iii int
    )
    insert into a values(1,11,111)
    insert into a values(2,11,111)
    insert into a values(3,11,111)
    insert into a values(4,18,111)
    insert into a values(7,81,111)
    commit transaction
      

  2.   

    conntemp.BeginTrans
    中间放程序
    conntemp.CommitTrans
      

  3.   

    create proc proc_my 
    as
    begin transaction 
    create table a(
    i tinyint,
    ii smallint,
    iii int
    )
    if @@error<>0  
    rollback
    insert into a values(1,11,111)
    if @@error<>0  
    rollback
    insert into a values(2,11,111)
    if @@error<>0  
    rollback
    insert into a values(3,11,111)
    if @@error<>0  
    rollback
    insert into a values(4,18,111)
    if @@error<>0  
    rollback
    insert into a values(7,81,111)
    if @@error<>0  
    rollback
    commit transaction
    这样对吗
      

  4.   

    begin tran
      insert into a values(1,11,111)
      insert into a values(2,11,111)
      insert into a values(3,11,111)
      insert into a values(4,18,111)
      insert into a values(7,81,111)
    commit tran
      

  5.   

    begin tran
      insert into a values(1,11,111)
      insert into a values(2,11,111)
      insert into a values(3,11,111)
      insert into a values(4,18,111)
      insert into a values(7,81,111)
    commit tran