O'Reilly logo

Inside Microsoft® SQL Server™ 2005: T-SQL Querying by Dejan Sarka, Lubor Kollar, Itzik Ben-Gan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Nested Sets

Nested sets is one of the most beautiful and intellectually stimulating solutions I’ve ever seen for modeling trees.

More Info

More Info

Joe Celko has extensive coverage of the Nested Sets model in his writings. You can find Joe Celko’s coverage of nested sets in his book, Joe Celko’s Trees and Hierarchies in SQL for Smarties (Morgan-Kaufmann, 2004).

Here I will cover T-SQL applications of the model, which for the most part work in SQL Server 2005 only because they use new features such as recursive CTEs and the ROW_NUMBER function.

The main advantages of the nested sets solution are simple and fast queries, which I’ll describe later, and no level ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required