简体   繁体   English

对商品进行数据库管理以存储其类别

[英]database management to goods to store their categories

I have to create a web site witch contain goods. 我必须创建一个包含商品的网站。 these goods have their own categories.for a example a good can be categorized in many categories or sub categories. 这些商品有其自己的类别。例如,商品可以分为许多类别或子类别。 I already have a item table witch contain their properties. 我已经有一个包含其属性的项目表巫婆。 and can anyone say how to keep it`s categories in database without duplicating data 谁能说出如何在不重复数据的情况下将其类别保留在数据库中

Ok. 好。 In this case an Item may have many categories and a category may have many Items. 在这种情况下,一个项目可能有许多类别,而一个类别可能有许多项目。 So its a many to many relationship. 因此,这是多对多的关系。 Try as follows, 尝试如下,

Your Item table may look like this, 您的项目表可能看起来像这样,

Item( id , description, amount, ... )

In your Category table, 在您的类别表中,

Category( id , name, description, ... )

And there will be another table to assign categories to items, 将会有另一个表格为商品分配类别,

ItemCategoryAssignments( itemId , categoryId )

And there will be two foreign keys at ItemCategoryAssignments table. 在ItemCategoryAssignments表上将有两个外键。 That, 那,

itemId references id in the Item tabel

and

categoryId references id in the Category tabel

Like that. 像那样。 There will be no duplicated rows. 将没有重复的行。 Hope this will help. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM