首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

请教,这段代码如何加事务?有几种办法

2012-12-15 
请问,这段代码怎么加事务?有几种办法。如题:我自己的办法是下面代码,不知道对否,请大家看看,或者有别的代码

请问,这段代码怎么加事务?有几种办法。
如题:我自己的办法是下面代码,不知道对否,请大家看看,
或者有别的代码没?

USE [LAPSBase]
GO
/****** Object:  StoredProcedure [dbo].[Pro_LAPS_InsertApproveReport]    Script Date: 11/22/2012 14:19:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[Pro_LAPS_InsertApproveReport]
@CIFNm nvarchar(50),
@ACNo nvarchar(50),
@CreditNo nvarchar(50),

-------系统字段-----
@PledgeType nvarchar(50),
@Cr_POBCType nvarchar(50),
@Cr_POBCRemark nvarchar(50),
@Cr_FQIZHANType nvarchar(50),
@Cr_FQIZHANMark nvarchar(50),
@Cr_GeRenDianhuaHecha nvarchar(50),
@Cr_GeRenDianhuaType nvarchar(50),
@Cr_GerenJuzhuDIType nvarchar(50),
@Cr_GerenJuzhuDITypeMark nvarchar(50),
@Cr_DTIType nvarchar(50),
@Cr_DTI nvarchar(50),
@Cr_CsmFinaFlowType nvarchar(50),
@CR_CsmFinaFlowExAmount nvarchar(50),
@CR_CsmFinaFlowExMonth nvarchar(50),
@CR_CsmFinaFlowExEvaluate nvarchar(50),
@Mo_MoType nvarchar(50),
@Mo_Yuguzhi nvarchar(50),
@Mo_Zhengshiguzhi nvarchar(50),
@Mo_DiYachengshu nvarchar(50),
@Mo_DiYaAmount nvarchar(50),
@Mo_DiyajineTotal nvarchar(50),
@Mo_MoMark nvarchar(50),
@Approvelimits nvarchar(50),
@Cons_ProductCode nvarchar(50),
@Cons_IsApproveCondition nvarchar(50),
@Cons_NormalPasson nvarchar(50),
@Cons_AttenionResume nvarchar(50),
@Cons_MoName nvarchar(50),
@Cons_RefuseValue nvarchar(50),
----定义从表-审批意见的参数----
@OperCode nvarchar(50),
@OperIdeas nvarchar(50),
----定义从表-财务参数----
@Fn_FileType nvarchar(50),
@Fn_CheckPeriodStart nvarchar(50),
@Fn_CheckPeriodEnd nvarchar(50),
@Fn_Income nvarchar(50),
@Fn_PayAmout nvarchar(50),
@Fn_ValidityType nvarchar(50),
@Fn_Remark nvarchar(50)


AS
BEGIN

SET XACT_ABORT ON 

begin tran
     insert into ApproveReprotMain
     (
CIFNm,
ACNo,
CreditNo,
PledgeType,
Cr_POBCType,
Cr_POBCRemark,
Cr_FQIZHANType,
Cr_FQIZHANMark,
Cr_GeRenDianhuaHecha,
Cr_GeRenDianhuaType,
Cr_GerenJuzhuDIType,
Cr_GerenJuzhuDITypeMark,
Cr_DTIType,
Cr_DTI,
Cr_CsmFinaFlowType,
CR_CsmFinaFlowExAmount,
CR_CsmFinaFlowExMonth,
CR_CsmFinaFlowExEvaluate,
Mo_MoType,
Mo_Yuguzhi,
Mo_Zhengshiguzhi,
Mo_DiYachengshu,
Mo_DiYaAmount,
Mo_DiyajineTotal,
Mo_MoMark,
Approvelimits,
Cons_ProductCode,
Cons_IsApproveCondition,
Cons_NormalPasson,
Cons_AttenionResume,
Cons_MoName,
Cons_RefuseValue
     )
     values 
     (
@CIFNm,
@ACNo,
@CreditNo,
@PledgeType,
@Cr_POBCType,
@Cr_POBCRemark,
@Cr_FQIZHANType,
@Cr_FQIZHANMark,
@Cr_GeRenDianhuaHecha,
@Cr_GeRenDianhuaType,
@Cr_GerenJuzhuDIType,
@Cr_GerenJuzhuDITypeMark,
@Cr_DTIType,
@Cr_DTI,
@Cr_CsmFinaFlowType,
@CR_CsmFinaFlowExAmount,
@CR_CsmFinaFlowExMonth,
@CR_CsmFinaFlowExEvaluate,
@Mo_MoType,
@Mo_Yuguzhi,
@Mo_Zhengshiguzhi,
@Mo_DiYachengshu,
@Mo_DiYaAmount,
@Mo_DiyajineTotal,
@Mo_MoMark,
@Approvelimits,
@Cons_ProductCode,
@Cons_IsApproveCondition,
@Cons_NormalPasson,
@Cons_AttenionResume,
@Cons_MoName,
@Cons_RefuseValue
     )
     


insert into ApproveReprotBr_Ideas    
     (
      ACNo,
      CreditNo,
      OperCode,
      OperIdeas
     )
     values
     (
      @ACNo,
      @CreditNo,
      @OperCode,
      @OperIdeas
     )
     
 insert into ApproveReportBr_Financial 
     (
      Fn_FileType,
      Fn_CheckPeriodStart,
      Fn_CheckPeriodEnd,
      Fn_Income,
      Fn_PayAmout,
      Fn_ValidityType,
      Fn_Remark 
     )
     values
     (
      @Fn_FileType,
      @Fn_CheckPeriodStart,
      @Fn_CheckPeriodEnd,
      @Fn_Income,
      @Fn_PayAmout,
      @Fn_ValidityType,
      @Fn_Remark 
     )
  COMMIT TRAN    
  SET XACT_ABORT OFF
     
END


[最优解释]
没什么问题吧
[其他解释]
1.@@error<>0 判断法:
你的语句 
if @@error<>0
commit
else
rollback

2. try catch 机制:
begin try
begin tran
  你的代码
commit
end try
begin catch
rollback
end catch
[其他解释]
应该没有问题

热点排行