多级类别的数据库结构(最佳方法) [英] Database structure for multi-level category (Best Approach)
问题描述
该用户对该数据库结构的问题所做的处理方式正常。然而,在关系数据库方法思考中,多级别类别数据库的最佳方法是什么?
The approach this user made on this question for the database structure works fine. However, thinking in a relational database approach, what is the best approach for a multi-level category database?
推荐答案
非常简单有效
我们只是做一个递归关联。
id title content parent_id
==============================================
1 item1 NULL NULL
2 item2 NULL 1
3 item3 abcd 2
4 item4 efgh 2
在此示例中:
item1
是第一级(请参阅 parent_id
是 NULL
)。
item1
is the first level (see that the parent_id
is NULL
).
item2
是 item1
的第二级选项(请参阅 parent_id
是 1
而内容
是 NULL
仅使另一个钻取选项)。
item2
is a second level option from item1
(see that the parent_id
is 1
and the content
is NULL
making this another drill down option only).
item3
和 item4
的内容来自 item2
(见 parent_id
是 2
和内容
NOT null)。
item3
and item4
are content from item2
(see that parent_id
is 2
and the content
is NOT null).
这篇关于多级类别的数据库结构(最佳方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!