【发布时间】:2018-03-06 00:36:29
【问题描述】:
我有一个产品,它可以属于 5 个可能类别中的一个(或多个)。
类别的数量/名称/结构不会改变
我应该使用多对多关系并在类别表中插入 5 条记录,添加连接表并添加外键等吗?或者只是在产品表中添加 5 个字段?我觉得后者似乎更有效,但违背了规范化的原则。
即
Product:
- id
- name
- is_cat_a : bool
- is_cat_b : bool
- is_cat_c : bool
- is_cat_d : bool
- is_cat_e : bool
或
Product
- id
- name
Category
- id
- name
ProductCategories
- product_id
- category_id
【问题讨论】: