CREATE TABLE [dbo].[pr_products_branches]
(
[prdb_product_code] [dbo].[ais_code_short] NOT NULL,
[prdb_branch_id] [int] NOT NULL,
[prdb_currency_code] [dbo].[ais_code_short] NOT NULL,
[prdb_account_number] [varchar] (50) COLLATE French_CI_AS NULL,
[prdb_excel_file_name] [varchar] (100) COLLATE French_CI_AS NULL,
[prdb_freeze] [bit] NOT NULL CONSTRAINT [DF__pr_products_branches__prdb_freeze] DEFAULT ((0)),
[prdb_hd_show_franchise] [bit] NOT NULL CONSTRAINT [DF__pr_products_branches__prdb_hd_show_franchise] DEFAULT ((0)),
[prdb_hd_show_franchise_mini] [bit] NOT NULL CONSTRAINT [DF__pr_products_branches__prdb_hd_show_franchise_mini] DEFAULT ((0)),
[prdb_hd_show_franchise_maxi] [bit] NOT NULL CONSTRAINT [DF__pr_products_branches__prdb_hd_show_franchise_maxi] DEFAULT ((0)),
[prdb_hd_show_capital] [bit] NOT NULL CONSTRAINT [DF__pr_products_branches__prdb_hd_show_capital] DEFAULT ((0)),
[prdb_days_ur] [tinyint] NULL,
[prdb_days_fn] [tinyint] NULL,
[prdb_mvt_code__fn] [dbo].[ais_code_short] NULL,
[prdb_days_fnr] [tinyint] NULL,
[prdb_mvt_code__fnr] [dbo].[ais_code_short] NULL,
[prdb_days_cs] [tinyint] NULL,
[prdb_mvt_code__cs] [dbo].[ais_code_short] NULL,
[prdb_days_ct] [tinyint] NULL,
[prdb_mvt_code__ct] [dbo].[ais_code_short] NULL,
[prdb_cts_fee] [dbo].[ais_decimal2] NULL,
[prdb_document_relative_path_pn] [varchar] (512) COLLATE French_CI_AS NULL,
[prdb_output_type_code__pn] [dbo].[ais_code_short] NULL,
[prdb_sequence_code__pn] [dbo].[ais_code_short] NULL,
[prdb_pagebreak_code__pn] [dbo].[ais_code_short] NULL,
[prdb_mail_code__pn] [dbo].[ais_code_short] NULL,
[prdb_document_relative_path_pr] [varchar] (512) COLLATE French_CI_AS NULL,
[prdb_output_type_code__pr] [dbo].[ais_code_short] NULL,
[prdb_sequence_code__pr] [dbo].[ais_code_short] NULL,
[prdb_pagebreak_code__pr] [dbo].[ais_code_short] NULL,
[prdb_mail_code__pr] [dbo].[ais_code_short] NULL,
[prdb_document_relative_path_ur] [varchar] (512) COLLATE French_CI_AS NULL,
[prdb_output_type_code__ur] [dbo].[ais_code_short] NULL,
[prdb_sequence_code__ur] [dbo].[ais_code_short] NULL,
[prdb_pagebreak_code__ur] [dbo].[ais_code_short] NULL,
[prdb_mail_code__ur] [dbo].[ais_code_short] NULL,
[prdb_document_relative_path_fn] [varchar] (512) COLLATE French_CI_AS NULL,
[prdb_output_type_code__fn] [dbo].[ais_code_short] NULL,
[prdb_sequence_code__fn] [dbo].[ais_code_short] NULL,
[prdb_pagebreak_code__fn] [dbo].[ais_code_short] NULL,
[prdb_mail_code__fn] [dbo].[ais_code_short] NULL,
[prdb_document_relative_path_fnr] [varchar] (512) COLLATE French_CI_AS NULL,
[prdb_output_type_code__fnr] [dbo].[ais_code_short] NULL,
[prdb_sequence_code__fnr] [dbo].[ais_code_short] NULL,
[prdb_pagebreak_code__fnr] [dbo].[ais_code_short] NULL,
[prdb_mail_code__fnr] [dbo].[ais_code_short] NULL,
[prdb_document_relative_path_cs] [varchar] (512) COLLATE French_CI_AS NULL,
[prdb_output_type_code__cs] [dbo].[ais_code_short] NULL,
[prdb_sequence_code__cs] [dbo].[ais_code_short] NULL,
[prdb_pagebreak_code__cs] [dbo].[ais_code_short] NULL,
[prdb_mail_code__cs] [dbo].[ais_code_short] NULL,
[prdb_document_relative_path_ct] [varchar] (512) COLLATE French_CI_AS NULL,
[prdb_output_type_code__ct] [dbo].[ais_code_short] NULL,
[prdb_sequence_code__ct] [dbo].[ais_code_short] NULL,
[prdb_pagebreak_code__ct] [dbo].[ais_code_short] NULL,
[prdb_mail_code__ct] [dbo].[ais_code_short] NULL,
[prdb_company_id] [int] NULL,
[prdb_monthly_payment_yesno_code] [varchar] (1) COLLATE French_CI_AS NULL,
[prdb_notice_period] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [CK_pr_products_branches_prdb_pagebreak_code__cs] CHECK ((isnull([prdb_pagebreak_code__cs],'P')<>'I'))
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [CK_pr_products_branches_prdb_pagebreak_code__ct] CHECK ((isnull([prdb_pagebreak_code__ct],'P')<>'I'))
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [CK_pr_products_branches_prdb_pagebreak_code__fn] CHECK ((isnull([prdb_pagebreak_code__fn],'P')<>'I'))
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [CK_pr_products_branches_prdb_pagebreak_code__fnr] CHECK ((isnull([prdb_pagebreak_code__fnr],'P')<>'I'))
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [PK_pr_products_branches] PRIMARY KEY CLUSTERED  ([prdb_product_code], [prdb_branch_id]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_acc_currencies] FOREIGN KEY ([prdb_currency_code]) REFERENCES [dbo].[acc_currencies] ([cur_currency_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_act_accounts] FOREIGN KEY ([prdb_branch_id], [prdb_account_number]) REFERENCES [dbo].[act_accounts] ([acc_actor_id], [acc_account_number])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_act_branches] FOREIGN KEY ([prdb_branch_id]) REFERENCES [dbo].[act_branches] ([br_actor_id])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_act_cies] FOREIGN KEY ([prdb_company_id]) REFERENCES [dbo].[act_cies] ([cie_actor_id])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_documents_output_types] FOREIGN KEY ([prdb_output_type_code__pn]) REFERENCES [dbo].[nm_documents_output_types] ([nmdot_output_type_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_documents_output_types1] FOREIGN KEY ([prdb_output_type_code__pr]) REFERENCES [dbo].[nm_documents_output_types] ([nmdot_output_type_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_documents_output_types2] FOREIGN KEY ([prdb_output_type_code__ur]) REFERENCES [dbo].[nm_documents_output_types] ([nmdot_output_type_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_documents_output_types3] FOREIGN KEY ([prdb_output_type_code__fn]) REFERENCES [dbo].[nm_documents_output_types] ([nmdot_output_type_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_documents_output_types4] FOREIGN KEY ([prdb_output_type_code__fnr]) REFERENCES [dbo].[nm_documents_output_types] ([nmdot_output_type_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_documents_output_types5] FOREIGN KEY ([prdb_output_type_code__cs]) REFERENCES [dbo].[nm_documents_output_types] ([nmdot_output_type_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_documents_output_types6] FOREIGN KEY ([prdb_output_type_code__ct]) REFERENCES [dbo].[nm_documents_output_types] ([nmdot_output_type_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_mails] FOREIGN KEY ([prdb_mail_code__pn]) REFERENCES [dbo].[nm_mails] ([mail_mail_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_mails1] FOREIGN KEY ([prdb_mail_code__pr]) REFERENCES [dbo].[nm_mails] ([mail_mail_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_mails2] FOREIGN KEY ([prdb_mail_code__ur]) REFERENCES [dbo].[nm_mails] ([mail_mail_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_mails3] FOREIGN KEY ([prdb_mail_code__fn]) REFERENCES [dbo].[nm_mails] ([mail_mail_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_mails4] FOREIGN KEY ([prdb_mail_code__fnr]) REFERENCES [dbo].[nm_mails] ([mail_mail_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_mails5] FOREIGN KEY ([prdb_mail_code__cs]) REFERENCES [dbo].[nm_mails] ([mail_mail_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_mails6] FOREIGN KEY ([prdb_mail_code__ct]) REFERENCES [dbo].[nm_mails] ([mail_mail_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_page_breaks] FOREIGN KEY ([prdb_pagebreak_code__pn]) REFERENCES [dbo].[nm_page_breaks] ([pb_pagebreak_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_page_breaks1] FOREIGN KEY ([prdb_pagebreak_code__pr]) REFERENCES [dbo].[nm_page_breaks] ([pb_pagebreak_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_page_breaks2] FOREIGN KEY ([prdb_pagebreak_code__ur]) REFERENCES [dbo].[nm_page_breaks] ([pb_pagebreak_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_page_breaks3] FOREIGN KEY ([prdb_pagebreak_code__fn]) REFERENCES [dbo].[nm_page_breaks] ([pb_pagebreak_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_page_breaks4] FOREIGN KEY ([prdb_pagebreak_code__fnr]) REFERENCES [dbo].[nm_page_breaks] ([pb_pagebreak_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_page_breaks5] FOREIGN KEY ([prdb_pagebreak_code__cs]) REFERENCES [dbo].[nm_page_breaks] ([pb_pagebreak_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_page_breaks6] FOREIGN KEY ([prdb_pagebreak_code__ct]) REFERENCES [dbo].[nm_page_breaks] ([pb_pagebreak_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_nm_yesno_values] FOREIGN KEY ([prdb_monthly_payment_yesno_code]) REFERENCES [dbo].[nm_yesno_values] ([nmvyn_yesno_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_pol_mvts] FOREIGN KEY ([prdb_mvt_code__fn]) REFERENCES [dbo].[pol_mvts] ([pmvt_mvt_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_pol_mvts1] FOREIGN KEY ([prdb_mvt_code__fnr]) REFERENCES [dbo].[pol_mvts] ([pmvt_mvt_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_pol_mvts2] FOREIGN KEY ([prdb_mvt_code__cs]) REFERENCES [dbo].[pol_mvts] ([pmvt_mvt_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_pol_mvts3] FOREIGN KEY ([prdb_mvt_code__ct]) REFERENCES [dbo].[pol_mvts] ([pmvt_mvt_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_pr_products] FOREIGN KEY ([prdb_product_code]) REFERENCES [dbo].[pr_products] ([prd_product_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_sq_sequences] FOREIGN KEY ([prdb_sequence_code__ct]) REFERENCES [dbo].[sq_sequences] ([seq_sequence_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_sq_sequences1] FOREIGN KEY ([prdb_sequence_code__cs]) REFERENCES [dbo].[sq_sequences] ([seq_sequence_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_sq_sequences2] FOREIGN KEY ([prdb_sequence_code__fnr]) REFERENCES [dbo].[sq_sequences] ([seq_sequence_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_sq_sequences3] FOREIGN KEY ([prdb_sequence_code__fn]) REFERENCES [dbo].[sq_sequences] ([seq_sequence_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_sq_sequences4] FOREIGN KEY ([prdb_sequence_code__ur]) REFERENCES [dbo].[sq_sequences] ([seq_sequence_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_sq_sequences5] FOREIGN KEY ([prdb_sequence_code__pr]) REFERENCES [dbo].[sq_sequences] ([seq_sequence_code])
GO
ALTER TABLE [dbo].[pr_products_branches] ADD CONSTRAINT [FK_pr_products_branches_sq_sequences6] FOREIGN KEY ([prdb_sequence_code__pn]) REFERENCES [dbo].[sq_sequences] ([seq_sequence_code])
GO
