CREATE TABLE [dbo].[ATEventDefinition] (
    [EventID]            INT            NOT NULL IDENTITY(1,1),
    [ProcessID]          INT            NOT NULL,
    [EventName]          NVARCHAR (255) NOT NULL,
    [PositionX]          INT            NULL,
    [PositionY]          INT            NULL,
    [EventTypeID]        INT            NOT NULL,
    [Server]             NVARCHAR (255) NULL,
    [ExpirationInterval] INT            NULL,
    [JoinEventID]        INT            NULL,
    [ProcessAtServer]    INT            NOT NULL,
    [Script]             IMAGE          NULL,
    [ScriptLanguage]     INT            NULL,
    [ExScript]           IMAGE          NULL,
    [ExpirationInstance] NVARCHAR (50)  NULL,
    [NextEventID]        INT            NULL,
    [Action]             NVARCHAR (64)  NULL,
    CONSTRAINT [PK_EventDefinition] PRIMARY KEY NONCLUSTERED ([EventID] ASC),
    CONSTRAINT [UK_EventDefinition_Process_EventName_Action] UNIQUE ([ProcessID], [EventName], [Action]),
    CONSTRAINT [ATEventDefinition_ATEventType] FOREIGN KEY (EventTypeID) REFERENCES [dbo].[ATEventType] ([Id]),
    CONSTRAINT [ATEventDefinition_ATProcessDefinition] FOREIGN KEY ([ProcessID]) REFERENCES [dbo].[ATProcessDefinition] ([ProcessID]),
    CONSTRAINT [ATEventDefinition_ATEventDefinition] FOREIGN KEY ([JoinEventID]) REFERENCES [dbo].[ATEventDefinition] ([EventID]),
    CONSTRAINT [ATEventDefinition_ATServer] FOREIGN KEY ([Server]) REFERENCES [dbo].[ATServer] ([HostName])
);


GO
CREATE NONCLUSTERED INDEX [ATEventDefinition_IX_Expire]
    ON [dbo].[ATEventDefinition]([ExpirationInterval] ASC);
