Sql Server 中事务(begin tran/commit tran/rollback tran)的用法

ALTER PROCEDURE [dbo].[Proc_Test_commit1] 
	@result int output,	--成功 1; 失败 0
	@message nvarchar(20) output 
AS
BEGIN
	SET NOCOUNT ON
	
begin try 
	  begin tran yy 
        insert into Test_Commit (b) values (3)

        insert into Test_Commit (a,b) values (1,3)
        set @result=1
	  commit tran yy	 		
                  end try	
begin catch
		set @message= ERROR_MESSAGE() 
		set @result=0
		rollback tran yy		
		--insert into SYS_Proc_Message([Message]) values(ERROR_MESSAGE())
		print ERROR_MESSAGE()
end catch 
	
	SET NOCOUNT OFF;  
	
	
END

 

posted @ 2012-02-22 11:42  诺哥的传奇  阅读(14442)  评论(0编辑  收藏  举报