Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

Chapter 4: Nested Sets Model of Hierarch... > 4.8 Inserting and Updating Trees - Pg. 96

4 . 8 I n s e r t i n g a n d U p d a t i n g Tr e e s 83 CREATE VIEW TotalWeight (part, qty, wgt, lft, rgt) AS SELECT part, qty, WgtCalc(part, lft, rgt) FROM Frammis; Of course, the UPDATE is now trivial ... UPDATE Frammis SET wgt = WgtCalc(part); 4.8 Inserting and Updating Trees Updates to nodes are done by searching for the key of each node; there is nothing special about them. However, rearranging the structure of the tree is tricky because figuring out the (lft, rgt) nested sets numbers requires a good bit of algebra in a large tree. As a programming project, you might want to build a tool that takes a "boxes-and-arrows" graphic and converts it into a series of UPDATE and INSERT statements. Inserting a subtree or a new node involves finding a place in the tree for the new