我读了那么多博客和链接来保存mysql数据库中的分层数据,比如、嵌套集、模态、*传递、笨拙、模式*、父级Hierchy。但是我有点困惑,能不能请任何人给我建议一下,什么是最好的方法来存储多个根的层次。
e.g
Root1
|
|---Child 1
| |--Child 1 of 1
| |--Child 2 of 2
|
Root 2
|
|--Child 2
| |--Child 1 of 2
| |--Child 2 of 2
(致谢:)
发布于 2013-05-10 18:16:56
当使用表存储层次结构时,层次结构中的每个对象都需要一个父对象。因此,您的节点可能有以下列:
nodeid int not null not zero the id of the node in this row
parentid int not null, but can be zero the id the node's parent
nodename varchar the node's name
etc etc. other attributes of the node
使用此表布局,任何无父节点(即任何具有parentid = 0
的节点)都是根节点。您可以根据您的应用程序的需要,在您的表中拥有其中的任意数量。
您展示的示例可能表示如下:
nodeid parentid nodename
------ -------- --------
1 0 Root1
2 1 Child 1
3 2 Child 1 of 1
4 2 Child 2 of 1
5 0 Root2
6 5 Child 2
7 6 Child 1 of 2
8 6 Child 2 of 2
https://stackoverflow.com/questions/16488241
复制相似问题