CREATE TABLE [dbo].[ATFieldInstanceOption] (
    [FieldInstanceID] INT            NOT NULL IDENTITY(1,1),
    [FieldID]         INT            NOT NULL,
    [FieldValue]      NVARCHAR (MAX) NULL,
    [WorkItemID]      INT            NOT NULL,
    [FieldName]       NVARCHAR (64)  NOT NULL,
    CONSTRAINT [PK_ATFieldInstanceOption] PRIMARY KEY NONCLUSTERED ([FieldInstanceID] ASC),
    CONSTRAINT [ATFieldInstanceOption_ATFieldDefinition] FOREIGN KEY ([FieldID]) REFERENCES [dbo].[ATFieldDefinition] ([FieldID]),
    CONSTRAINT [ATFieldInstanceOption_ATWorkItem] FOREIGN KEY ([WorkItemID]) REFERENCES [dbo].[ATWorkItem] ([WorkItemId])
);


GO
CREATE NONCLUSTERED INDEX [ATFieldInstanceOption_IX_FId]
    ON [dbo].[ATFieldInstanceOption]([FieldID] ASC);


GO
CREATE NONCLUSTERED INDEX [ATFieldInstanceOption_IX_FName]
    ON [dbo].[ATFieldInstanceOption]([FieldName] ASC);


GO
CREATE NONCLUSTERED INDEX [ATFieldInstanceOption_IX_WIId]
    ON [dbo].[ATFieldInstanceOption]([WorkItemID] ASC);

