Шаблон ХП

/******************************************************************************
**	
*******************************************************************************/
create procedure dbo.
as
set nocount on
set xact_abort on
declare @transactionCount int
begin try
	--
	set @transactionCount = @@trancount
	if (@transactionCount = 0)
		begin transaction

	--
	
	if (@transactionCount = 0)
		commit transaction
end try
begin catch
	declare @errorNumber int, @errorMessage nvarchar(4000), @errorSeverity int, @errorState int
	
	select 
		@errorNumber = error_number(),
		@errorMessage = error_message(),
		@errorSeverity = error_severity(),
		@errorState = error_state();
		
	if (@transactionCount = 0 and @@trancount > 0)
		rollback transaction;
		
	raiserror(@errorMessage, @errorSeverity, @errorState)
end catch;

Last updated