DB Schema 设计 Parent Children grand children
DB Schema design Parent Children grand children
您好,我正在研究一种创建具有以下结构的关系数据库的方法
Parent
-Child 1
-Grand Child 1
-Child 2
-Grand child 2
但是 grand child 2 也可以是 child 1
的一部分
如果 parent 可以有 n children 而 child 可以有 n grand children 那很好,使用 RMDBS 非常简单。
当您想 'n' 更深入地使用 grand grand children 并且 grand children 可以是多个 children 的一部分时,问题就出现了。
一个很好的例子是 ebay 对其产品的分类。
在数据库中创建这样的动态 tree/web 的正确方法是什么?
来自我的:
In a more complex model, e.g. different car models sharing the same
motor model (and it's not clear whether you are talking about car
models, or specific cars), the ParentEntityId column would be replaced
by a relation table:
TABLE Entity (Id, Name, EntityTypeId)
TABLE EntityHierarchy (Id, ParentEntityId, ChildEntityId)
The entries in the EntityHierarchy table would be constrained (on
application level) by the tree of EntityTypes
您好,我正在研究一种创建具有以下结构的关系数据库的方法
Parent
-Child 1
-Grand Child 1
-Child 2
-Grand child 2
但是 grand child 2 也可以是 child 1
的一部分如果 parent 可以有 n children 而 child 可以有 n grand children 那很好,使用 RMDBS 非常简单。
当您想 'n' 更深入地使用 grand grand children 并且 grand children 可以是多个 children 的一部分时,问题就出现了。
一个很好的例子是 ebay 对其产品的分类。
在数据库中创建这样的动态 tree/web 的正确方法是什么?
来自我的
In a more complex model, e.g. different car models sharing the same motor model (and it's not clear whether you are talking about car models, or specific cars), the ParentEntityId column would be replaced by a relation table:
TABLE Entity (Id, Name, EntityTypeId)
TABLE EntityHierarchy (Id, ParentEntityId, ChildEntityId)
The entries in the EntityHierarchy table would be constrained (on application level) by the tree of EntityTypes