[dbo].[FactoringBatchDetail]
CREATE TABLE [dbo].[FactoringBatchDetail]
(
[FactoringBatchDetailID] [int] NOT NULL IDENTITY(1, 1),
[FactoringBatchFID] [int] NOT NULL,
[InvoicedHeaderFID] [int] NOT NULL,
[InvoiceAmount] [money] NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[FactoringBatchDetail] ADD CONSTRAINT [PK_FactoringBatchDetail] PRIMARY KEY NONCLUSTERED ([FactoringBatchDetailID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[FactoringBatchDetail] ADD CONSTRAINT [IX_FactoringBatchDetail_Batch_Invoice] UNIQUE NONCLUSTERED ([FactoringBatchFID], [InvoicedHeaderFID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[FactoringBatchDetail] ADD CONSTRAINT [FK_FactoringBatch_FactoringBatch] FOREIGN KEY ([FactoringBatchFID]) REFERENCES [dbo].[FactoringBatch] ([FactoringBatchID]) ON DELETE CASCADE
GO
ALTER TABLE [dbo].[FactoringBatchDetail] ADD CONSTRAINT [FK_FactoringBatch_InvoicedHeader] FOREIGN KEY ([InvoicedHeaderFID]) REFERENCES [dbo].[InvoicedHeader] ([IHPriKey])
GO
GRANT SELECT ON [dbo].[FactoringBatchDetail] TO [MssExec]
GRANT INSERT ON [dbo].[FactoringBatchDetail] TO [MssExec]
GRANT DELETE ON [dbo].[FactoringBatchDetail] TO [MssExec]
GRANT UPDATE ON [dbo].[FactoringBatchDetail] TO [MssExec]
GO