CREATE TABLE [dbo].[pr_families_variables]
(
[pfv_family_code] [dbo].[ais_code_short] NOT NULL,
[pfv_variable_code] [dbo].[ais_code_short] NOT NULL,
[pfv_rowver] [timestamp] NOT NULL,
[pfv_optional] [bit] NOT NULL CONSTRAINT [DF__pr_families_variables__pfv_optional] DEFAULT ((0)),
[pfv_variable_code__parent] [dbo].[ais_code_short] NULL
) ON [PRIMARY]
ALTER TABLE [dbo].[pr_families_variables] ADD
CONSTRAINT [FK_pr_families_variables_pr_families_variables] FOREIGN KEY ([pfv_family_code], [pfv_variable_code__parent]) REFERENCES [dbo].[pr_families_variables] ([pfv_family_code], [pfv_variable_code])
ALTER TABLE [dbo].[pr_families_variables] ADD
CONSTRAINT [FK_pr_families_variables_pr_families] FOREIGN KEY ([pfv_family_code]) REFERENCES [dbo].[pr_families] ([pf_family_code]) ON UPDATE CASCADE


GO







ALTER TABLE [dbo].[pr_families_variables] ADD CONSTRAINT [PK_pr_families_variables] PRIMARY KEY CLUSTERED  ([pfv_family_code], [pfv_variable_code]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[pr_families_variables] ADD CONSTRAINT [FK_pr_families_variables_nm_products_variables] FOREIGN KEY ([pfv_variable_code]) REFERENCES [dbo].[nm_products_variables] ([nmpv_variable_code])
GO
