Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Left and Right in Nested Set Model

Status
Not open for further replies.
Oct 11, 2006
300
US
Hi,

I would like to convert my adjancey set model to a nested set model with a left and right.

I understood this part.

Root Node is always with a a Left = 1, right = 2*(Select Count(*) from Table)

How do the leaf node get the left and right numbers.

I was reading an article of Joe Celko regarding the Nested Sets in SQL and I could not understand how do the employee below Albert(who is top level manager) get their node numbers.

Code:
Adjanceny Model
--------------------------------------------
Emp    Boss

Albert  Null
Bert    Albert
Chuck   Albert
Donna   Chuck
Eddie   Chuck
Fred    Chuck

Nested Set Model
----------------------------------------
Emp    Left     Right
Albert   1        12
Bert     2         3
Chuck    4        11
Donna    5         6
Eddie    7         8
Fred     9         10

If anyone could kindly explain this to me, then I can try converting my table to a nested set model to prevent recursion.

I am using SQL Server 2000

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top