I have to store a hierarchical tree into a SQL database. After a search here on the site I found a couple solutions, but I still need some help.
In short, I have “inputs” that must be routed to outputs, based on the type of input signal, the place in the tree and the time.
To make it a bit more complex I have the requirement that it should be work with MSSQL server 2005, MySQL and SQL lite. Maybe I can drop the SQL lite requirement at some time, but for now I have to deal with it.
Most common action taken on the tree is that I have to search from bottom up to the root node for a node with some information attached to it.
The easiest way to implement this seems to me to create a table with references to the parent and selecting first the bottom node, check if the information is attached to it; if not select the parent and repeat.
While simple and not require any special database functionality it require many queries. Up to 6 levels of node nesting will be common, at most 14 levels are expected.
The information that is attached to a node contain some time (period of day/week) depended link between a type of input and the output that I have to find. Below an example; when input 1 on “Node 4” is activated I want to find that the output should be “4”, if input 8 is activated on the same node the output should be “0”.
where I have to look for more background information about this kind of structures or does anyone have an idea how to design the database structure for this problem?
Edit:
In response to the answer from Young Bob I will do a test. But if someone has an idea for me to do a select (...) if not exist repeat for parent, and so on in one query I'm very interested.