What is the best way to build the table that will represent the tree?
I want to implement a select ,insert ,update and delete that will work well with big data.
The select for example will have to support “Expand ALL” – getting all the children (and there children) for a given node.
What is the best way to build the table that will represent the tree?
Share
Use
CTE‘s.Given the tree-like table structure:
, this query will return
id,parentand depth level, ordered as a tree:Replace
parent = 0withparent = @parentto get only a branch of a tree.Provided there’s an index on
table (parent), this query will efficiently work on a very large table, since it will recursively useINDEX LOOKUPto find all chilrden for each parent.To update a certain branch, issue:
where
@parentis the root of the branch.