CREATE TABLE [dbo].[doc_collections_docs]
(
[dcd_document_id] [int] NOT NULL,
[dcd_collection_id] [int] NOT NULL,
[dcd_status_code] [dbo].[ais_code_short] NOT NULL,
[dcd_document_relative_path] [varchar] (512) COLLATE French_CI_AS NULL,
[dcd_pagebreak_code] [dbo].[ais_code_short] NOT NULL,
[dcd_output_type_code] [dbo].[ais_code_short] NOT NULL,
[dcd_sequence_code] [dbo].[ais_code_short] NULL,
[dcd_mail_code] [dbo].[ais_code_short] NULL,
[dcd_number] [dbo].[ais_code_long] NULL,
[dcd_object_id] [int] NULL,
[dcd_actor_id] [int] NOT NULL,
[dcd_policy_id] [int] NULL,
[dcd_policy_situation_id] [int] NULL,
[dcd_account_id] [int] NULL,
[dcd_claim_id] [int] NULL,
[dcd_obs] [nvarchar] (512) COLLATE French_CI_AS NULL,
[dcd_mail_utc_date] [datetime] NULL,
[dcd_mail_guid] [varchar] (64) COLLATE French_CI_AS NULL
) ON [PRIMARY]
ALTER TABLE [dbo].[doc_collections_docs] ADD 
CONSTRAINT [PK_doc_collections_docs] PRIMARY KEY CLUSTERED  ([dcd_document_id]) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [IX_doc_collections_docs_guid] ON [dbo].[doc_collections_docs] ([dcd_mail_guid]) ON [PRIMARY]

ALTER TABLE [dbo].[doc_collections_docs] ADD
CONSTRAINT [FK_doc_collections_docs_pol_policies] FOREIGN KEY ([dcd_policy_id]) REFERENCES [dbo].[pol_policies] ([pol_policy_id])



ALTER TABLE [dbo].[doc_collections_docs] ADD
CONSTRAINT [FK_doc_collections_docs_acc_accounts] FOREIGN KEY ([dcd_account_id]) REFERENCES [dbo].[acc_accounts] ([a_account_id])
ALTER TABLE [dbo].[doc_collections_docs] ADD
CONSTRAINT [FK_doc_collections_docs_claim_claims] FOREIGN KEY ([dcd_claim_id]) REFERENCES [dbo].[claim_claims] ([cl_claim_id])
ALTER TABLE [dbo].[doc_collections_docs] ADD
CONSTRAINT [FK_doc_collections_docs_nm_mails] FOREIGN KEY ([dcd_mail_code]) REFERENCES [dbo].[nm_mails] ([mail_mail_code])
ALTER TABLE [dbo].[doc_collections_docs] ADD
CONSTRAINT [FK_doc_collections_docs_nm_documents_output_types] FOREIGN KEY ([dcd_output_type_code]) REFERENCES [dbo].[nm_documents_output_types] ([nmdot_output_type_code])
ALTER TABLE [dbo].[doc_collections_docs] ADD
CONSTRAINT [FK_doc_collections_docs_nm_page_breaks] FOREIGN KEY ([dcd_pagebreak_code]) REFERENCES [dbo].[nm_page_breaks] ([pb_pagebreak_code])
ALTER TABLE [dbo].[doc_collections_docs] ADD
CONSTRAINT [FK_doc_collections_docs_pol_policies_situations] FOREIGN KEY ([dcd_policy_situation_id]) REFERENCES [dbo].[pol_policies_situations] ([pols_policy_situation_id])
ALTER TABLE [dbo].[doc_collections_docs] ADD
CONSTRAINT [FK_doc_collections_docs_sq_sequences] FOREIGN KEY ([dcd_sequence_code]) REFERENCES [dbo].[sq_sequences] ([seq_sequence_code])
GO

ALTER TABLE [dbo].[doc_collections_docs] ADD CONSTRAINT [FK_doc_collections_docs_act_actors] FOREIGN KEY ([dcd_actor_id]) REFERENCES [dbo].[act_actors] ([act_actor_id])
GO
ALTER TABLE [dbo].[doc_collections_docs] ADD CONSTRAINT [FK_doc_collections_docs_doc_collections] FOREIGN KEY ([dcd_collection_id]) REFERENCES [dbo].[doc_collections] ([dc_collection_id])
GO
ALTER TABLE [dbo].[doc_collections_docs] ADD CONSTRAINT [FK_doc_collections_docs_doc_collections_docs_statuses] FOREIGN KEY ([dcd_status_code]) REFERENCES [dbo].[doc_collections_docs_statuses] ([dcds_status_code])
GO
