
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure [dbo].[p_test_product_delete]
	@product_code ais_code_short
as

	delete	pr_products_variables_introducers 
	where	prdvi_product_code = @product_code

	delete	pr_products_variables_taxes		
	where	prdvt_variable_id in
			(
			select	distinct prdv_variable_id
			from	pr_products_variables
			where	prdv_product_code = @product_code
			)


	alter table pr_products_variables disable trigger all
	delete	pr_products_variables
	where	prdv_product_code = @product_code
	alter table pr_products_variables enable trigger all

	delete	pr_products_introducers
	where	prdint_product_code = @product_code

	delete	pr_products_documents
	where	prdd_product_code = @product_code

	delete	pr_products_branches
	where	prdb_product_code = @product_code

	delete	usr_users_products
	where	usrp_product_code = @product_code

	delete	pr_products
	where	prd_product_code = @product_code


GO
