CREATE TABLE [dbo].[InvoicedImage]
(
[InvoicedImageID] [int] NOT NULL IDENTITY(1, 1),
[InvoicedHeaderFID] [int] NOT NULL,
[InvoicedImage] [image] NOT NULL,
[ReportTypeFID] [smallint] NOT NULL,
[ReportArchiveTypeFID] [int] NULL,
[ImageByteSize] AS (datalength([InvoicedImage]))
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[InvoicedImage] ADD CONSTRAINT [pk_InvoicedImage] PRIMARY KEY CLUSTERED ([InvoicedImageID]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_InvoicedImage_InvoicedHeaderFID] ON [dbo].[InvoicedImage] ([InvoicedHeaderFID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[InvoicedImage] ADD CONSTRAINT [FK_InvoicedImage_InvoicedHeader] FOREIGN KEY ([InvoicedHeaderFID]) REFERENCES [dbo].[InvoicedHeader] ([IHPriKey]) ON DELETE CASCADE
GO
ALTER TABLE [dbo].[InvoicedImage] ADD CONSTRAINT [FK_InvoicedImage_ReportArchiveType] FOREIGN KEY ([ReportArchiveTypeFID]) REFERENCES [dbo].[ReportArchiveType] ([ReportArchiveTypeID])
GO
ALTER TABLE [dbo].[InvoicedImage] ADD CONSTRAINT [FK_InvoicedImage_ReportType] FOREIGN KEY ([ReportTypeFID]) REFERENCES [dbo].[ReportType] ([ReportTypeID])
GO
GRANT SELECT ON [dbo].[InvoicedImage] TO [MssExec]
GRANT INSERT ON [dbo].[InvoicedImage] TO [MssExec]
GRANT DELETE ON [dbo].[InvoicedImage] TO [MssExec]
GRANT UPDATE ON [dbo].[InvoicedImage] TO [MssExec]
GO