我指的是Bill Karwin 的演示文稿,以实现一个有助于我管理层次结构的闭包表。不幸的是,演示文稿没有显示我如何插入/更新Level
幻灯片 67 中提到的列;这将非常有用。我一直在考虑,但我无法提出可以测试的具体内容。这是我到目前为止得到的:
create procedure USP_OrganizationUnitHierarchy_AddChild
@ParentId UNIQUEIDENTIFIER,
@NewChildId UNIQUEIDENTIFIER
AS
BEGIN
INSERT INTO [OrganizationUnitHierarchy]
(
[AncestorId],
[DescendantId],
[Level]
)
SELECT [AncestorId], @NewChildId, (here I need to get the count of ancestors that lead to the currently being selected ancestor through-out the tree)
FROM [OrganizationUnitHierarchy]
WHERE [DescendantId] = @ParentId
UNION ALL SELECT @NewChildId, @NewChildId
END
go
我不确定我该怎么做。有任何想法吗?