CREATE TABLE [dbo].[pr_products_variables_introducers]
(
[prdvi_variable_id] [int] NOT NULL,
[prdvi_product_code] [dbo].[ais_code_short] NOT NULL,
[prdvi_branch_id] [int] NOT NULL,
[prdvi_introducer_id] [int] NOT NULL,
[prdvi_retro_code] [dbo].[ais_code_short] NOT NULL
) ON [PRIMARY]
ALTER TABLE [dbo].[pr_products_variables_introducers] ADD
CONSTRAINT [FK_pr_products_variables_introducers_pr_products_variables] FOREIGN KEY ([prdvi_variable_id]) REFERENCES [dbo].[pr_products_variables] ([prdv_variable_id]) ON DELETE CASCADE
ALTER TABLE [dbo].[pr_products_variables_introducers] ADD CONSTRAINT [PK_pr_products_variables_introducers] PRIMARY KEY NONCLUSTERED  ([prdvi_variable_id], [prdvi_product_code], [prdvi_branch_id], [prdvi_introducer_id]) ON [PRIMARY]

ALTER TABLE [dbo].[pr_products_variables_introducers] ADD
CONSTRAINT [FK_pr_products_variables_introducers_pr_products_introducers] FOREIGN KEY ([prdvi_product_code], [prdvi_branch_id], [prdvi_introducer_id]) REFERENCES [dbo].[pr_products_introducers] ([prdint_product_code], [prdint_branch_id], [prdint_introducer_id])



GO

ALTER TABLE [dbo].[pr_products_variables_introducers] ADD CONSTRAINT [FK_pr_products_variables_int_int_retrocessions] FOREIGN KEY ([prdvi_retro_code]) REFERENCES [dbo].[int_retrocessions] ([iret_retro_code])
GO
