CREATE TABLE [dbo].[policies_replaced_invoices]
(
[prli_lot_id] [int] NOT NULL,
[prli_source_invoice_id] [int] NOT NULL,
[prli_cancel_invoice_id] [int] NULL,
[prli_new_invoice_id] [int] NULL,
[prli_reimboursed_invoice_id] [int] NULL,
[prli_transaction_succeded] [bit] NOT NULL CONSTRAINT [DF__policies_replaced_invoices__prli_transaction_succeded] DEFAULT ((0)),
[prli_crystal_error_code] [dbo].[ais_code_long] NULL,
[prli_error_description] [nvarchar] (2000) COLLATE French_CI_AS NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[policies_replaced_invoices] ADD CONSTRAINT [PK_policies_replaced_invoices] PRIMARY KEY CLUSTERED  ([prli_lot_id], [prli_source_invoice_id]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[policies_replaced_invoices] ADD CONSTRAINT [FK_policies_replaced_invoices_acc_invoices] FOREIGN KEY ([prli_source_invoice_id]) REFERENCES [dbo].[acc_invoices] ([inv_invoice_id])
GO
ALTER TABLE [dbo].[policies_replaced_invoices] ADD CONSTRAINT [FK_policies_replaced_invoices_acc_invoices1] FOREIGN KEY ([prli_cancel_invoice_id]) REFERENCES [dbo].[acc_invoices] ([inv_invoice_id])
GO
ALTER TABLE [dbo].[policies_replaced_invoices] ADD CONSTRAINT [FK_policies_replaced_invoices_acc_invoices2] FOREIGN KEY ([prli_new_invoice_id]) REFERENCES [dbo].[acc_invoices] ([inv_invoice_id])
GO
ALTER TABLE [dbo].[policies_replaced_invoices] ADD CONSTRAINT [FK_policies_replaced_invoices_acc_invoices3] FOREIGN KEY ([prli_reimboursed_invoice_id]) REFERENCES [dbo].[acc_invoices] ([inv_invoice_id])
GO
ALTER TABLE [dbo].[policies_replaced_invoices] ADD CONSTRAINT [FK_policies_replaced_invoices_crystal_errors_codes] FOREIGN KEY ([prli_crystal_error_code]) REFERENCES [dbo].[crystal_errors_codes] ([cec_crystal_error_code])
GO
ALTER TABLE [dbo].[policies_replaced_invoices] ADD CONSTRAINT [FK_policies_replaced_invoices_policies_replaced_lots] FOREIGN KEY ([prli_lot_id]) REFERENCES [dbo].[policies_replaced_lots] ([prl_lot_id])
GO
