多级类别的数据库结构(最佳方法) [英] Database structure for multi-level category (Best Approach)

查看:181
本文介绍了多级类别的数据库结构(最佳方法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该用户对该数据库结构的问题所做的处理方式正常。然而,在关系数据库方法思考中,多级别类别数据库的最佳方法是什么?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆