Link to home
Start Free TrialLog in
Avatar of OFGemini
OFGemini

asked on

how to Validate Hierarchy in a Nested Sets Model

Hello Experts,

I store Hierarchical data in SQL server using the Nested sets model.  After editing my tree (moves, adds, deletes...), how do I validate that the hierarchy in my Nested Sets Model is valid still?  I want to ensure that I don't lose any branches of my tree.

Thanks,
OFGemini
Avatar of jogos
jogos
Flag of Belgium image

If you mean validate after insert/update -> walk through tree and eventualy
- report problems
- move loose ends to a 'loose end' hierarchy
Avatar of OFGemini
OFGemini

ASKER

jogos,

Yes, how do you walk through the tree?  When you walk through the tree wouldn't you only find 'not loose items' only?
ASKER CERTIFIED SOLUTION
Avatar of jogos
jogos
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
how do you query for gaps?
I am not a SQL expert but I doubt that finding a query for gaps is possible.

To check for the duplicates/gaps, what I would do is using a loop to fill all the the left-right values as keys of an array.
Then, using a second loop, I would check if each key is equal to the previous key +1.
In the end, the array should contain values = 2x the count() of the array and the first value should be 1.