CREATE TABLE [dbo].[ATDocument] (
    [DocumentId]    INT            NOT NULL IDENTITY(1,1),
    [DocumentName]  NVARCHAR (255) NULL,
    [ReviewStatusId]  INT          NOT NULL DEFAULT (1),
    [ReviewNumber]  INT            NOT NULL DEFAULT (1),
    [CabinetId]     INT            NOT NULL,
    [WorkItemId]    INT            NOT NULL,
    [DocumentSize]  INT            NOT NULL,
    [DisplayOrder]  INT            NULL,
    [Document]      IMAGE          NULL,
    [DocumentLink]  NVARCHAR (255) NULL,
    [UserName]      NVARCHAR (255) NULL,
    [SignedBy]      NVARCHAR (255) NULL,
    [LastModified]  DATETIME       NOT NULL DEFAULT(GETDATE()),
    CONSTRAINT [PK_ATDocument] PRIMARY KEY CLUSTERED ([DocumentId] ASC),
    CONSTRAINT [ATDocument_FK_Cabinet] FOREIGN KEY ([CabinetId]) REFERENCES [dbo].[ATDocumentCabinet] ([CabinetID]),
    CONSTRAINT [ATDocument_FK_WorkItemId] FOREIGN KEY ([WorkItemId]) REFERENCES [dbo].[ATWorkItem] ([WorkItemId]),
    CONSTRAINT [ATDocument_FK_ReviewStatusId] FOREIGN KEY ([ReviewStatusId]) REFERENCES [dbo].[ATDocumenctReviewStatus] ([Id])
);


GO
CREATE NONCLUSTERED INDEX [ATDocument_IX_WorkItemId]
    ON [dbo].[ATDocument]([WorkItemId] ASC);

