如何在数据库中管理类别和产品 [英] how to manage category and product in database

查看:89
本文介绍了如何在数据库中管理类别和产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,我该如何管理数据库中的类别和产品可以帮助我...

主要类别
1.干洗

子类别
1.男人
2.女人

产品主厨
1.烟灰1
2.烟灰1次分类
2.毛巾2第二个类别

hi dear friends how can i manage category and product in database can nay one help me...

main category
1. dry clean

sub category
1. men
2. women

products maincatoery
1. piece soot 1
2. soot 1 second category
2. towel 2 second category

推荐答案

假设层次结构的级别可以变化,则不能简单地使用树表.在这里查看: http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/ [ ^ ]
Supposing that the level of hierarchy can vary, you can not simply use tree tables. Look here: http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/[^]


由于您有一个带有可能的子类别的类别,因此我将其建模为分层数据(
Since you have a category with possible subcategories I''d go for modeling this as hierarchical data (More Trees & Hierarchies in SQL[^]).

You''d end up with a table like below for the categories:
(-1 indicates that a category does not have a parent and is thus a root category)
ID    Name      Description        ParentID
1     Dry Clean Dry cleaning stuff -1
2     Men       Clothes for men     1
3     Woman     Clothes for women   1



然后,您需要一种方法来关联哪些产品属于哪个类别,以便创建关联:

ProductsPerCategory



Then you need a means to relate which products are in which category so you''d create a relation:

ProductsPerCategory

CategoryID ProductID
1          1
2          2
3          3



问候,

—曼弗雷德(Manfred)



Regards,

— Manfred


这篇关于如何在数据库中管理类别和产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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