CREATE TABLE [dbo].[cts_chains]
(
[ctsch_chain_code] [dbo].[ais_code_short] NOT NULL,
[ctsch_l1] [nvarchar] (64) COLLATE French_CI_AS NOT NULL,
[ctsch_l2] [nvarchar] (64) COLLATE French_CI_AS NULL,
[ctsch_l3] [nvarchar] (64) COLLATE French_CI_AS NULL,
[ctsch_days_ur] [tinyint] NOT NULL CONSTRAINT [DF_cts_chains_ctsch_days_ur] DEFAULT ((0)),
[ctsch_days_fn] [tinyint] NOT NULL CONSTRAINT [DF_cts_chains_ctsch_days_fn] DEFAULT ((0)),
[ctsch_mvt_code__fn] [dbo].[ais_code_short] NOT NULL,
[ctsch_days_fnr] [tinyint] NOT NULL CONSTRAINT [DF_cts_chains_ctsch_days_fnr] DEFAULT ((0)),
[ctsch_mvt_code__fnr] [dbo].[ais_code_short] NOT NULL,
[ctsch_days_cs] [tinyint] NOT NULL CONSTRAINT [DF_cts_chains_ctsch_days_cs] DEFAULT ((0)),
[ctsch_mvt_code__cs] [dbo].[ais_code_short] NOT NULL,
[ctsch_days_ct] [tinyint] NOT NULL CONSTRAINT [DF_cts_chains_ctsch_days_ct] DEFAULT ((0)),
[ctsch_mvt_code__ct] [dbo].[ais_code_short] NOT NULL,
[ctsch_cts_fee] [dbo].[ais_decimal2] NULL,
[ctsch_document_relative_path_pn] [varchar] (512) COLLATE French_CI_AS NULL,
[ctsch_output_type_code__pn] [dbo].[ais_code_short] NULL,
[ctsch_sequence_code__pn] [dbo].[ais_code_short] NULL,
[ctsch_pagebreak_code__pn] [dbo].[ais_code_short] NULL,
[ctsch_mail_code__pn] [dbo].[ais_code_short] NULL,
[ctsch_document_relative_path_pr] [varchar] (512) COLLATE French_CI_AS NULL,
[ctsch_output_type_code__pr] [dbo].[ais_code_short] NULL,
[ctsch_sequence_code__pr] [dbo].[ais_code_short] NULL,
[ctsch_pagebreak_code__pr] [dbo].[ais_code_short] NULL,
[ctsch_mail_code__pr] [dbo].[ais_code_short] NULL,
[ctsch_document_relative_path_ur] [varchar] (512) COLLATE French_CI_AS NULL,
[ctsch_output_type_code__ur] [dbo].[ais_code_short] NULL,
[ctsch_sequence_code__ur] [dbo].[ais_code_short] NULL,
[ctsch_pagebreak_code__ur] [dbo].[ais_code_short] NULL,
[ctsch_mail_code__ur] [dbo].[ais_code_short] NULL,
[ctsch_document_relative_path_fn] [varchar] (512) COLLATE French_CI_AS NULL,
[ctsch_output_type_code__fn] [dbo].[ais_code_short] NULL,
[ctsch_sequence_code__fn] [dbo].[ais_code_short] NULL,
[ctsch_pagebreak_code__fn] [dbo].[ais_code_short] NULL,
[ctsch_mail_code__fn] [dbo].[ais_code_short] NULL,
[ctsch_document_relative_path_fnr] [varchar] (512) COLLATE French_CI_AS NULL,
[ctsch_output_type_code__fnr] [dbo].[ais_code_short] NULL,
[ctsch_sequence_code__fnr] [dbo].[ais_code_short] NULL,
[ctsch_pagebreak_code__fnr] [dbo].[ais_code_short] NULL,
[ctsch_mail_code__fnr] [dbo].[ais_code_short] NULL,
[ctsch_document_relative_path_cs] [varchar] (512) COLLATE French_CI_AS NULL,
[ctsch_output_type_code__cs] [dbo].[ais_code_short] NULL,
[ctsch_sequence_code__cs] [dbo].[ais_code_short] NULL,
[ctsch_pagebreak_code__cs] [dbo].[ais_code_short] NULL,
[ctsch_mail_code__cs] [dbo].[ais_code_short] NULL,
[ctsch_document_relative_path_ct] [varchar] (512) COLLATE French_CI_AS NULL,
[ctsch_output_type_code__ct] [dbo].[ais_code_short] NULL,
[ctsch_sequence_code__ct] [dbo].[ais_code_short] NULL,
[ctsch_pagebreak_code__ct] [dbo].[ais_code_short] NULL,
[ctsch_mail_code__ct] [dbo].[ais_code_short] NULL,
[ctsch_notice_period] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [CK_cts_chains_ctsch_pagebreak_code__cs] CHECK ((isnull([ctsch_pagebreak_code__cs],'P')<>'I'))
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [CK_cts_chains_ctsch_pagebreak_code__ct] CHECK ((isnull([ctsch_pagebreak_code__ct],'P')<>'I'))
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [CK_cts_chains_ctsch_pagebreak_code__fn] CHECK ((isnull([ctsch_pagebreak_code__fn],'P')<>'I'))
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [CK_cts_chains_ctsch_pagebreak_code__fnr] CHECK ((isnull([ctsch_pagebreak_code__fnr],'P')<>'I'))
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [CK__cts_chains_ctsch_chain_code__string_pk] CHECK ((len(ltrim(rtrim([ctsch_chain_code])))>(0) AND charindex('*',[ctsch_chain_code])=(0) AND charindex('%',[ctsch_chain_code])=(0)))
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [PK_cts_chains] PRIMARY KEY CLUSTERED  ([ctsch_chain_code]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_documents_output_types_cs] FOREIGN KEY ([ctsch_output_type_code__cs]) REFERENCES [dbo].[nm_documents_output_types] ([nmdot_output_type_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_documents_output_types_ct] FOREIGN KEY ([ctsch_output_type_code__ct]) REFERENCES [dbo].[nm_documents_output_types] ([nmdot_output_type_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_documents_output_types_fn] FOREIGN KEY ([ctsch_output_type_code__fn]) REFERENCES [dbo].[nm_documents_output_types] ([nmdot_output_type_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_documents_output_types_fnr] FOREIGN KEY ([ctsch_output_type_code__fnr]) REFERENCES [dbo].[nm_documents_output_types] ([nmdot_output_type_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_documents_output_types_pn] FOREIGN KEY ([ctsch_output_type_code__pn]) REFERENCES [dbo].[nm_documents_output_types] ([nmdot_output_type_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_documents_output_types_pr] FOREIGN KEY ([ctsch_output_type_code__pr]) REFERENCES [dbo].[nm_documents_output_types] ([nmdot_output_type_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_documents_output_types_ur] FOREIGN KEY ([ctsch_output_type_code__ur]) REFERENCES [dbo].[nm_documents_output_types] ([nmdot_output_type_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_mails] FOREIGN KEY ([ctsch_mail_code__pn]) REFERENCES [dbo].[nm_mails] ([mail_mail_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_mails1] FOREIGN KEY ([ctsch_mail_code__pr]) REFERENCES [dbo].[nm_mails] ([mail_mail_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_mails2] FOREIGN KEY ([ctsch_mail_code__ur]) REFERENCES [dbo].[nm_mails] ([mail_mail_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_mails3] FOREIGN KEY ([ctsch_mail_code__fn]) REFERENCES [dbo].[nm_mails] ([mail_mail_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_mails4] FOREIGN KEY ([ctsch_mail_code__fnr]) REFERENCES [dbo].[nm_mails] ([mail_mail_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_mails5] FOREIGN KEY ([ctsch_mail_code__cs]) REFERENCES [dbo].[nm_mails] ([mail_mail_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_mails6] FOREIGN KEY ([ctsch_mail_code__ct]) REFERENCES [dbo].[nm_mails] ([mail_mail_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_page_breaks] FOREIGN KEY ([ctsch_pagebreak_code__pn]) REFERENCES [dbo].[nm_page_breaks] ([pb_pagebreak_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_page_breaks1] FOREIGN KEY ([ctsch_pagebreak_code__pr]) REFERENCES [dbo].[nm_page_breaks] ([pb_pagebreak_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_page_breaks2] FOREIGN KEY ([ctsch_pagebreak_code__ur]) REFERENCES [dbo].[nm_page_breaks] ([pb_pagebreak_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_page_breaks3] FOREIGN KEY ([ctsch_pagebreak_code__fn]) REFERENCES [dbo].[nm_page_breaks] ([pb_pagebreak_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_page_breaks4] FOREIGN KEY ([ctsch_pagebreak_code__fnr]) REFERENCES [dbo].[nm_page_breaks] ([pb_pagebreak_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_page_breaks5] FOREIGN KEY ([ctsch_pagebreak_code__cs]) REFERENCES [dbo].[nm_page_breaks] ([pb_pagebreak_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_nm_page_breaks6] FOREIGN KEY ([ctsch_pagebreak_code__ct]) REFERENCES [dbo].[nm_page_breaks] ([pb_pagebreak_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_pol_mvts] FOREIGN KEY ([ctsch_mvt_code__fn]) REFERENCES [dbo].[pol_mvts] ([pmvt_mvt_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_pol_mvts1] FOREIGN KEY ([ctsch_mvt_code__fnr]) REFERENCES [dbo].[pol_mvts] ([pmvt_mvt_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_pol_mvts2] FOREIGN KEY ([ctsch_mvt_code__cs]) REFERENCES [dbo].[pol_mvts] ([pmvt_mvt_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_pol_mvts3] FOREIGN KEY ([ctsch_mvt_code__ct]) REFERENCES [dbo].[pol_mvts] ([pmvt_mvt_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_sq_sequences_cs] FOREIGN KEY ([ctsch_sequence_code__cs]) REFERENCES [dbo].[sq_sequences] ([seq_sequence_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_sq_sequences_ct] FOREIGN KEY ([ctsch_sequence_code__ct]) REFERENCES [dbo].[sq_sequences] ([seq_sequence_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_sq_sequences_fn] FOREIGN KEY ([ctsch_sequence_code__fn]) REFERENCES [dbo].[sq_sequences] ([seq_sequence_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_sq_sequences_fnr] FOREIGN KEY ([ctsch_sequence_code__fnr]) REFERENCES [dbo].[sq_sequences] ([seq_sequence_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_sq_sequences_pn] FOREIGN KEY ([ctsch_sequence_code__pn]) REFERENCES [dbo].[sq_sequences] ([seq_sequence_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_sq_sequences_pr] FOREIGN KEY ([ctsch_sequence_code__pr]) REFERENCES [dbo].[sq_sequences] ([seq_sequence_code])
GO
ALTER TABLE [dbo].[cts_chains] ADD CONSTRAINT [FK_cts_chains_sq_sequences_ur] FOREIGN KEY ([ctsch_sequence_code__ur]) REFERENCES [dbo].[sq_sequences] ([seq_sequence_code])
GO
