CREATE TABLE [dbo].[ATXmlHierarchyDefinition] (
    [Id] INT IDENTITY(1,1) NOT NULL,
    [Name] NVARCHAR(255) NOT NULL,
    [Level] INT NOT NULL CHECK ([Level] BETWEEN 1 AND 20),
    [HierarchId] INT NULL, -- ref to New table ATXmlHierarchy (Id Name Description)
    [ParentId] INT NULL,
    CONSTRAINT [PK_ATXmlHierarchyDefinition] PRIMARY KEY CLUSTERED ([Id] ASC),
    CONSTRAINT [FK_ATXmlHierarchyDefinition_ParentId] FOREIGN KEY ([ParentId])
        REFERENCES [dbo].[ATXmlHierarchyDefinition] ([Id]),
    CONSTRAINT [FK_ATXmlHierarchyDefinition_HierarchId] FOREIGN KEY ([HierarchId])
        REFERENCES [dbo].[ATXmlHierarchy] ([Id])
);
GO

CREATE NONCLUSTERED INDEX [IX_ATXmlHierarchyDefinition_ParentId]
ON [dbo].[ATXmlHierarchyDefinition] ([ParentId]);
