[dbo].[OutgoingEmailInvoiceAttachment]
CREATE TABLE [dbo].[OutgoingEmailInvoiceAttachment]
(
[OutgoingEmailInvoiceAttachmentId] [int] NOT NULL IDENTITY(1, 1),
[OutgoingEmailFID] [int] NOT NULL,
[InvoicedHeaderFID] [int] NOT NULL,
[AttachmentOrder] [int] NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[OutgoingEmailInvoiceAttachment] ADD CONSTRAINT [PK_OutgoingEmailInvoiceAttachment] PRIMARY KEY NONCLUSTERED ([OutgoingEmailInvoiceAttachmentId]) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_OutgoingEmailInvoiceAttachment_OutgoingEmailFID_AttachmentOrder] ON [dbo].[OutgoingEmailInvoiceAttachment] ([OutgoingEmailFID], [AttachmentOrder]) ON [PRIMARY]
GO
CREATE UNIQUE CLUSTERED INDEX [IX_OutgoingEmailInvoiceAttachment_OutgoingEmailFID_InvoicedHeaderFID] ON [dbo].[OutgoingEmailInvoiceAttachment] ([OutgoingEmailFID], [InvoicedHeaderFID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[OutgoingEmailInvoiceAttachment] ADD CONSTRAINT [FK_OutgoingEmailInvoiceAttachment_InvoicedHeader] FOREIGN KEY ([InvoicedHeaderFID]) REFERENCES [dbo].[InvoicedHeader] ([IHPriKey]) ON DELETE CASCADE
GO
ALTER TABLE [dbo].[OutgoingEmailInvoiceAttachment] ADD CONSTRAINT [FK_OutgoingEmailInvoiceAttachment_OutgoingEmail] FOREIGN KEY ([OutgoingEmailFID]) REFERENCES [dbo].[OutgoingEmail] ([OutgoingEmailID]) ON DELETE CASCADE
GO
GRANT SELECT ON [dbo].[OutgoingEmailInvoiceAttachment] TO [MssExec]
GRANT INSERT ON [dbo].[OutgoingEmailInvoiceAttachment] TO [MssExec]
GRANT DELETE ON [dbo].[OutgoingEmailInvoiceAttachment] TO [MssExec]
GRANT UPDATE ON [dbo].[OutgoingEmailInvoiceAttachment] TO [MssExec]
GO