CREATE TABLE [dbo].[ATXmlTemplateDefinition] (
    [Id] INT IDENTITY(1,1) NOT NULL,
    [TemplateId] INT NOT NULL,
    [FieldName] NVARCHAR(255) NOT NULL,
    [FieldSourceId] INT NOT NULL,
    [XmlName] NVARCHAR(255) NOT NULL,
    [XmlParentId] INT NULL,
    CONSTRAINT [PK_ATXmlTemplateDef] PRIMARY KEY CLUSTERED ([Id] ASC),
    CONSTRAINT [FK_ATXmlTemplateDef_TemplateId] FOREIGN KEY ([TemplateId]) REFERENCES [dbo].[ATTemplates] ([Id]),
    CONSTRAINT [FK_ATXmlTemplateDef_FieldSourceId] FOREIGN KEY ([FieldSourceId]) REFERENCES [dbo].[ATExportType] ([Id]),
    CONSTRAINT [FK_ATXmlTemplateDef_XmlParentId] FOREIGN KEY ([XmlParentId]) REFERENCES [dbo].[ATXmlHierarchyDefinition] ([Id])  ON DELETE SET NULL
);
