CREATE TABLE [dbo].[MSSDocument]
(
[MSSDocumentID] [int] NOT NULL IDENTITY(1, 1),
[OrderFID] [int] NOT NULL,
[DocumentName] [nvarchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[SysUserFID] [int] NOT NULL,
[UploadDateTime] [datetime] NOT NULL,
[LastModified] [datetime] NOT NULL,
[ContentUrl] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[MSSDocumentImageFID] [int] NULL,
[DocumentTypeFID] [int] NOT NULL,
[DocumentDescription] [varchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[WorkTicketFID] [int] NULL,
[DocumentNotes] [varchar] (256) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[DocumentDeletionReasonFID] [int] NULL,
[DeletedBy] [int] NULL,
[DeletedOn] [datetime] NULL,
[SendToCrew] [bit] NOT NULL CONSTRAINT [DF_MSSDocument_SendToCrew] DEFAULT ((0)),
[DocByteSize] [int] NULL,
[IntegratorKeyID] [nvarchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[MSSDocument] ADD CONSTRAINT [PK_MSSDocument] PRIMARY KEY CLUSTERED ([MSSDocumentID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_MSSDocument_DeletedBy] ON [dbo].[MSSDocument] ([DeletedBy]) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_MSSDocument_Order_DocName_DeletedOn] ON [dbo].[MSSDocument] ([OrderFID], [DocumentName], [DeletedOn]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_MSSDocument_SysUserFID] ON [dbo].[MSSDocument] ([SysUserFID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[MSSDocument] ADD CONSTRAINT [FK_MSSDocument_SysUser2] FOREIGN KEY ([DeletedBy]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
ALTER TABLE [dbo].[MSSDocument] ADD CONSTRAINT [FK_MSSDocument_DocumentDeletionReason] FOREIGN KEY ([DocumentDeletionReasonFID]) REFERENCES [dbo].[DocumentDeletionReason] ([DocumentDeletionReasonID])
GO
ALTER TABLE [dbo].[MSSDocument] ADD CONSTRAINT [FK_MSSDocument_DocumentType] FOREIGN KEY ([DocumentTypeFID]) REFERENCES [dbo].[DocumentType] ([DocumentTypeID])
GO
ALTER TABLE [dbo].[MSSDocument] ADD CONSTRAINT [FK_MSSDocument_MSSDocumentImage] FOREIGN KEY ([MSSDocumentImageFID]) REFERENCES [dbo].[MSSDocumentImage] ([MSSDocumentImageID])
GO
ALTER TABLE [dbo].[MSSDocument] ADD CONSTRAINT [FK_MSSDocument_Orders] FOREIGN KEY ([OrderFID]) REFERENCES [dbo].[Orders] ([PriKey])
GO
ALTER TABLE [dbo].[MSSDocument] ADD CONSTRAINT [FK_MSSDocument_SysUser] FOREIGN KEY ([SysUserFID]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
ALTER TABLE [dbo].[MSSDocument] ADD CONSTRAINT [FK_MSSDocument_WorkTicket] FOREIGN KEY ([WorkTicketFID]) REFERENCES [dbo].[WorkTickets] ([WorkTicketID])
GO
GRANT SELECT ON [dbo].[MSSDocument] TO [MssExec]
GRANT INSERT ON [dbo].[MSSDocument] TO [MssExec]
GRANT DELETE ON [dbo].[MSSDocument] TO [MssExec]
GRANT UPDATE ON [dbo].[MSSDocument] TO [MssExec]
GO