CREATE TABLE [dbo].[ATProcessDefinition] (
    [ProcessID]          INT              NOT NULL IDENTITY (1, 1),
    [ProcessName]        NVARCHAR (255)   NOT NULL,
    [ProcessVersion]     INT              NOT NULL,
    [Description]        NVARCHAR (255)   NULL,
    [Versioning]         INT              NULL,
    [Status]             INT              NOT NULL,
    [Creator]            NVARCHAR (255)   NULL,
    [ProcessType]        INT              NOT NULL,
    [ExpirationInterval] INT              NULL,
    [LockedBy]           NVARCHAR (255)   NULL,
    [StopQueue]          NVARCHAR (32)    NULL,
    [ProcessGroupID]     INT              NULL,
    [StartEventID]       INT              NULL,
    [Script]             IMAGE            NULL,
    [Synchronous]        INT              NULL,
    [ScriptLanguage]     INT              NULL,
    [ExScript]           IMAGE            NULL,
    [WindowStyle]        NVARCHAR (1024)  NULL,
    [ObjectId]           UNIQUEIDENTIFIER NOT NULL,
    [Created]            DATETIME         NULL,
    [Map]                IMAGE            NULL,
    [DefaultDocTemplate] INT              NOT NULL DEFAULT 1,
    CONSTRAINT [PK_ProcessDefinition] PRIMARY KEY NONCLUSTERED ([ProcessID] ASC),
    CONSTRAINT [UK_ATProcessDefinition_ObjectId] UNIQUE ([ObjectId] ASC),
    CONSTRAINT [ATProcessDefinition_Creator] FOREIGN KEY ([Creator]) REFERENCES [dbo].[ATUser] ([UserName]),
    CONSTRAINT [ATProcessDefinition_LockedBy] FOREIGN KEY ([LockedBy]) REFERENCES [dbo].[ATUser] ([UserName]),
    CONSTRAINT [ATProcessDefinition_ProcessGroupID] FOREIGN KEY ([ProcessGroupID]) REFERENCES [dbo].[ATProcessGroup] ([ProcessGroupID]),
    CONSTRAINT [ATProcessDefinition_StartEventID] FOREIGN KEY ([StartEventID]) REFERENCES [dbo].[ATEventDefinition] ([EventID]),
    CONSTRAINT [ATProcessDefinition_ATDocumentCabinet] FOREIGN KEY ([DefaultDocTemplate]) REFERENCES [dbo].[ATDocumentCabinet] ([CabinetID])
);

GO
CREATE NONCLUSTERED INDEX [ATProcessDefinition_IX_ObjectId]
    ON [dbo].[ATProcessDefinition]([ObjectId] ASC);

GO
CREATE NONCLUSTERED INDEX [ATProcessDefinition_IX_Creator]
    ON [dbo].[ATProcessDefinition]([Creator] ASC);


GO
CREATE NONCLUSTERED INDEX [ATProcessDefinition_IX_GroupId]
    ON [dbo].[ATProcessDefinition]([ProcessGroupID] ASC);


GO
CREATE NONCLUSTERED INDEX [ATProcessDefinition_IX_Status]
    ON [dbo].[ATProcessDefinition]([Status] ASC);


GO
CREATE NONCLUSTERED INDEX [ATProcessDefinition_IX_Type]
    ON [dbo].[ATProcessDefinition]([ProcessType] ASC);


GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_ATProcessDefinition]
    ON [dbo].[ATProcessDefinition]([ProcessName] ASC, [ProcessVersion] ASC);

