【发布时间】:2013-09-04 19:56:35
【问题描述】:
我引用Bill Karwin's presentation 是为了实现一个有助于我管理层次结构的闭包表。不幸的是,演示文稿没有显示我如何插入/更新幻灯片 67 中提到的Level 列;这将非常有用。我一直在考虑,但我无法提出可以测试的具体内容。到目前为止,这是我得到的:
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
我不确定我该怎么做。有什么想法吗?
【问题讨论】:
标签: sql sql-server tsql stored-procedures transitive-closure-table