How do i store a directory / hierarchy / tree structure in the database? Namely MSSQL Server.
@olavk: Doesn't look like you've seen my own answer. The way i use is way better than recursive queries :)
p.p.s. This is the way to go!
...
            
           
          
            
            How would you get tree-structured data from a database with the best performance? For example, say you have a folder-hierarchy in a database. Where the folder-database-row has ID, Name and ParentID columns.
Would you use a special algorithm to get all the data at once, minimizing the amount of database-calls and process it in code?
Or ...
            
           
          
            
            Ok, so this shouldn't be difficult, however I have encountered weird and bizarra flukes. 
I am trying to pack a tree into an array, where each node is something like:
title: string-for-display
key: id-value
children: array of child nodes 
the fluke is so strange I can't comprehend it at all: when I try to add a child to a node, I do...
            
           
          
            
            Any node can have any number of children. To search this tree i wrote something like this
function Search(key, nodes){
 for (var i = 0; i < nodes.length; i++) {
        if (nodes[i].key == key) {
            return nodes[i];
        }
        if (nodes[i].hasOwnProperty('children')) {
            return this.Search(key, nodes[i].c...
            
           
          
            
            Hi.
My application uses some kind of "virtual folders" so I need to store the tree structure in the database. The table holding the data is quite simple, it has 3 columns:
id_folder (int, primary key)
id_parent (int, references id_folder)
folder_name (string)
My question is: which is the best way to implement the root?
Making id_p...