CREATE TABLE [dbo].[pr_products_variables_taxes]
(
[prdvt_variable_id] [int] NOT NULL,
[prdvt_tax_code] [dbo].[ais_code_short] NOT NULL,
[prdvt_branch_id] [int] NOT NULL,
[prdvt_payable_company] [bit] NOT NULL CONSTRAINT [DF__pr_products_variables_taxes__prdvt_payable_company] DEFAULT ((0)),
[prdvt_added_from_excel] [bit] NOT NULL CONSTRAINT [DF__pr_products_variables_taxes__prdvt_added_from_excel] DEFAULT ((0)),
[prdvt_calculated_in_excel] [bit] NOT NULL CONSTRAINT [DF__pr_products_variables_taxes__prdvt_calculated_in_excel] DEFAULT ((0))
) ON [PRIMARY]
ALTER TABLE [dbo].[pr_products_variables_taxes] ADD 
CONSTRAINT [PK_pr_products_variables_taxes] PRIMARY KEY CLUSTERED  ([prdvt_variable_id], [prdvt_tax_code], [prdvt_branch_id]) ON [PRIMARY]
ALTER TABLE [dbo].[pr_products_variables_taxes] ADD
CONSTRAINT [FK_pr_products_variables_taxes_act_branches] FOREIGN KEY ([prdvt_branch_id]) REFERENCES [dbo].[act_branches] ([br_actor_id])
ALTER TABLE [dbo].[pr_products_variables_taxes] ADD
CONSTRAINT [FK_pr_products_variables_taxes_pr_products_variables] FOREIGN KEY ([prdvt_variable_id]) REFERENCES [dbo].[pr_products_variables] ([prdv_variable_id]) ON DELETE CASCADE

GO

ALTER TABLE [dbo].[pr_products_variables_taxes] ADD CONSTRAINT [FK_pr_products_variables_taxes_nm_taxes] FOREIGN KEY ([prdvt_tax_code]) REFERENCES [dbo].[nm_taxes] ([nmtax_tax_code])
GO
