Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Site Related Forums
 Article Discussion
 More Trees & Hierarchies in SQL

Author  Topic 

giantg
Starting Member

1 Post

Posted - 2002-07-19 : 14:16:10
First off Rob, I would like to say how much I like this design for a hierarchy within a relational database. I've seen other's that use many more tables (i.e. not adjacent).. I've been trying to implement this system on MS SQL Server and I have come up with an ADD procedure.. I believe MOVE and PROMOTE will be pretty trivial, but I am stuck on the DELETE procedure. The only way I can figure to even start it is to use recursion. It seems that would be the only way to make sure no nodes are truncated (i.e. no parent, not root, just floating). Or would it be better to take this approach:

If a node with children is deleted, then the children will become children of that nodes parent...

i.e.

(root) (root)
| |
/ \ -----
/ \ / | \
/ \ Delete node 2 / | \
(node 1) (node 2) ============> / | | | / | ----- / \ / | --- / \ / | - / \ / | / \ (node 1) (node 3) (node 4)
(node 3) (node 4) | | |
| | ----- ----- -----
----- ----- --- --- ---
--- --- - - -
- -
--------Key---------+
| |
----- = Terminator |
--- |
- |
--------------------+



Any insight is appreciated, Thanks.
-Greg


   

- Advertisement -