O'Reilly logo

Programming Microsoft® SQL Server™ 2008 by Leonard Lobel, Andrew Brust, and Stephen Forte

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

Reordering Nodes Within the Hierarchy

Reorganizing a hierarchy is a common maintenance task. You might often need to alter the tree structure by changing the parent-child relationships within the hierarchy. The hierarchyid type provides a GetReparentedValue method that makes it easy to handle this kind of maintenance. We will start by first relocating just a single node without disturbing any other nodes in the hierarchy. Then we’ll relocate an entire subtree (that is, all of a node’s descendant nodes).

The GetReparentedValue Method

You invoke the GetReparentedValue method on the node you want to move, passing in two parameters. The first specifies the original parent (the source), and the second specifies the new parent (the target). Returning ...

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