简体   繁体   English

需要有关mysql数据库设计的建议

[英]need advice on mysql data base design

I need to build application where users can search/filter products by multiple characteristics. 我需要构建应用程序,用户可以通过多种特征搜索/过滤产品。 There are 25 product groups. 有25个产品组。 Each product group have around 10 product characteristics. 每个产品组都有大约10个产品特征。 I have a few data base design solutions, but none of them seems appropriate enough: 我有一些数据库设计解决方案,但它们似乎都不够合适:

  1. Create 25 tables per each group with column names storing product group characteristics. 每个组创建25个表,列名称存储产品组特征。
  2. Create one table with all products and as many columns as there are product characteristics (~ 200) 创建一个包含所有产品的表和包含产品特征的列数(~200)
  3. EAV: create 1 table for all characteristics and 1 table with all products and their attributes stored in rows, not in column names. EAV:为所有特征和1个表创建一个表,其中所有产品及其属性存储在行中,而不是列名中。 This solution will result in writing a lot of application code, because I won't be able to select a product with all characteristics in one row. 此解决方案将导致编写大量应用程序代码,因为我无法在一行中选择具有所有特征的产品。 I will have to write application code to group mysql results. 我将不得不编写应用程序代码来组合mysql结果。

I believe there are already solutions for problems like mine. 我相信已经解决了像我这样的问题。 Thanks for help. 感谢帮助。

EDIT: 编辑:

In most cases the characteristics in groups are entirely different. 在大多数情况下,组中的特征完全不同。 These are starter/alternator components. 这些是起动机/交流发电机组件。 Only around 25% of characteristics can overlap, like physical characteristics, length, diameter, etc. 只有大约25%的特征可以重叠,如物理特性,长度,直径等。

I would suggest the following: Create 3 tables; 我建议如下:创建3个表; Groups, GroupCharacteristics,Products. 群组,群体特征,产品。

  1. Groups is linked to both tables. 组链接到两个表。
  2. GroupCharacteristics will have the list of characteristics, using 3 columns, (1)GroupName,(2)CharacteristicName,(3)Mapping [Values for mapping could be C01,C02 through C10] You will use mapping later on. GroupCharacteristics将具有特征列表,使用3列,(1)GroupName,(2)CharacteristicsName,(3)Mapping [映射的值可以是C01,C02到C10]稍后您将使用映射。 One group has many characteristics so it's a one to many link. 一组具有许多特征,因此它是一对多的链接。
  3. Products will have 12 Columns; 产品将有12列; (1)ProductName/Id,(2)GroupName,(3)C01,(4)C02 ... (12)C10. (1)ProductName / Id,(2)GroupName,(3)C01,(4)C02 ......(12)C10。 The C** columns will be filled with the values of the related characteristics in order to keep them mapped correctly. C **列将填充相关特征的值,以便正确映射它们。

Groups: 团体:
[GroupName] [组名]
1-Vehicles 1-车辆
2-Furniture 2,家具
Characteristics: 特点:
[Map][Group][Characteristic] [地图] [集团] [特点]
1-C01 | 1-C01 | Vehicles | 车辆| Length 长度
2-C02 | 2-C02 | Vehicles | 车辆| Volume 体积
3-C03 | 3-C03 | Vehicles | 车辆| Type 类型
4-C01 | 4-C01 | Furniture | 家具| Height 高度
5-C02 | 5-C02 | Furniture | 家具| Volume 体积
6-C03 | 6-C03 | Furniture | 家具| Length 长度
Products: 产品介绍:
[ProdName][Group][C01][C02][C03]... [ProdName]的[组] [C01] [C02] [C03] ...
1-Car | 1车| Vehicles | 车辆| 2 | 2 | 50 | 50 | Hatchback 两厢
2-Jet | 2-Jet | Vehicles | 车辆| 10 | 10 | 70 | 70 | Null 空值
3-Table| 3,表| Furniture | 家具| 1 | 1 | null | null | 1.6 1.6
4-Cup | 4杯| Furniture |0.1 | 家具| 0.1 | 0.12 | 0.12 | null 空值

String col = Select Map from Characteristics where Group = 'Vehicles' and Characteristic = ' Type' String col =从特征中选择地图,其中Group ='Vehicles'和Characteristics ='Type'
-- this returns the column (in this case C03) then -- - 这将返回列(在本例中为C03)然后 -
String sql = "Select ProdName from Products where Group = 'Vehicles' and "+col+"='Hatchback'" String sql =“从产品中选择ProdName,其中Group ='Vehicles'和”+ col +“='Hatchback'”
-- this will build the query in a string then you just execute it -- - 这将在字符串中构建查询然后您只需执行它 -
execute(sql) 执行(SQL)
-- in whatever language you're using this is just the basic idea behind the code you have to write. - 无论您使用何种语言,这只是您必须编写的代码背后的基本思想。

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

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