> For the complete documentation index, see [llms.txt](https://projects.itproduct.ru/azimut/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://projects.itproduct.ru/azimut/dokumentaciya/shablon-khp.md).

# Шаблон ХП

```
/******************************************************************************
**	
*******************************************************************************/
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;
```
