数据库体系结构 - 使用多个值保留字段或创建新表

时间:2022-01-15 10:02:22

I am trying to figure out the MYSQL structure best practices for fields that contain more than one value. Should you ever have a field in a table that has comma separated values or should this logic always exist in a separate table?

我试图找出包含多个值的字段的MYSQL结构最佳实践。您是否在表中具有逗号分隔值的字段,或者该逻辑是否始终存在于单独的表中?

For Instance I have an Organization and Post table. Within this table I have the following fields:

对于实例,我有一个Organization和Post表。在此表中,我有以下字段:

Organization:

组织:

  • ID - Integer
  • ID - 整数
  • Organization Name - String
  • 组织名称 - 字符串
  • Admin - String
  • 管理员 - 字符串
  • Sources - String
  • 来源 - 字符串

Post:

帖子:

  • Post_ID - Integer
  • Post_ID - 整数
  • Title - String
  • 标题 - 字符串
  • Source - String (Value taken from list of "Sources")
  • Source - String(从“Sources”列表中获取的值)
  • Organization_ID - Integer (FK)
  • Organization_ID - 整数(FK)

My "Sources" field contains a predefined list of domains that can be individually selected for each "Post". Currently I have a record for an Organization that contains Sources like "wikipedia.org","google.com"

我的“来源”字段包含可以为每个“发布”单独选择的预定义域列表。目前我有一个包含“wikipedia.org”,“google.com”等来源的组织的记录

I was wondering if this is the best way to store the values or if "Sources" should be its own table and link to the Organization.

我想知道这是否是存储值的最佳方式,或者“源”是否应该是自己的表并链接到组织。

1 个解决方案

#1


0  

It definitely sounds like you should make a many-to-many relation between organization and source.

听起来你应该在组织和来源之间建立多对多的关系。

I.e. you make a new table which has the ids from organization and source as foreign keys.

即你创建一个新的表,其中组织和源的ID为外键。

#1


0  

It definitely sounds like you should make a many-to-many relation between organization and source.

听起来你应该在组织和来源之间建立多对多的关系。

I.e. you make a new table which has the ids from organization and source as foreign keys.

即你创建一个新的表,其中组织和源的ID为外键。