CREATE TABLE [dbo].[ATEventTriggerTemplate] (
    [Id]          INT            NOT NULL IDENTITY(1,1),
    [EventId]     INT            NOT NULL,
    [TemplateId]  INT            NOT NULL,
    [Order]       INT            NOT NULL,
    [Enabled]     BIT            NOT NULL DEFAULT 0,
    [Description] NVARCHAR(500)  NOT NULL,
    CONSTRAINT [PK_ATEventTriggerTemplate] PRIMARY KEY NONCLUSTERED ([Id] ASC),
    CONSTRAINT [UK_ATEventTriggerTemplate_EventId_TemplateId_Order] UNIQUE ([EventId] ASC, [TemplateId] ASC, [Order] ASC),
    CONSTRAINT [FK_ATEventTriggerTemplate_EventId] FOREIGN KEY ([EventId]) REFERENCES [dbo].[ATEventDefinition] ([EventId]),
    CONSTRAINT [FK_ATEventTriggerTemplate_TemplateId] FOREIGN KEY ([TemplateId]) REFERENCES [dbo].[ATTemplates] ([Id])
);
GO

CREATE CLUSTERED INDEX [IX_ATEventTriggerTemplate_EventId_Order_Clustered]
    ON [dbo].[ATEventTriggerTemplate] ([EventId], [TemplateId]);
    GO

