Modifying the Hierarchy

The script in Listing 42.15 performs the initial population of the Parts_hierarchy table. What if you need to add additional records into the table? Let’s look at how to use the GetDescendant method to add new records at different levels of the hierarchy.

For example, to add a child part to the Body node (node /2/), you can use the GetDescendant method without any arguments to add the new row below Body node at node /2/1/:

image

To add a new row as a higher descendant node at the same level as the left front fender inserted in the previous example, you use the GetDescendant method again, but this time passing the Hierarchyid ...

Get Microsoft® SQL Server 2008 R2 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.