CREATE TABLE [dbo].[ATStack] (
    [WorkItemRef]  INT NOT NULL,
    [EventId]      INT NOT NULL,
    [SubProcessId] INT NOT NULL,
    CONSTRAINT [PK_ATStack] PRIMARY KEY NONCLUSTERED ([WorkItemRef] ASC, [EventId] ASC),
    CONSTRAINT [ATStack_FK1] FOREIGN KEY ([EventId]) REFERENCES [dbo].[ATEventDefinition] ([EventID]),
    CONSTRAINT [ATStack_FK2] FOREIGN KEY ([WorkItemRef]) REFERENCES [dbo].[ATWorkItemReference] ([WorkItemReferenceId]),
    CONSTRAINT [ATStack_FK3] FOREIGN KEY ([SubProcessId]) REFERENCES [dbo].[ATProcessDefinition] ([ProcessID])
);


GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_ATStack]
    ON [dbo].[ATStack]([WorkItemRef] ASC, [SubProcessId] ASC);

