存储属性字段有多个值的对象

发布于 2025-01-02 03:10:34 字数 437 浏览 2 评论 0原文

我有一个数据存储要求,其中每个项目都有多个字段,并且每个字段可能包含多个值(字符串)。我需要运行一个搜索查询,其中将根据一个或多个字段值选择项目。这是我需要的结构:

Name:     (this will be the name of an item)
Season:   (name of the season)
Taste:    (1 taste or several)
Funktion: (1 or several option)
Weight:   (1 or several)
Volume:   (1 volume or several)
Tips:     (for comments)
Flavor combinations: (1 or several)
Matching flavors: (several)

请提供有关 MySql 的数据库设计搜索查询的任何建议。

I have a data storage requirement where each item has several fields and each field may contain more than one value (strings). And I need to run a Search query where item(s) will be selected based on one or more of the field values. here is structure what I need :

Name:     (this will be the name of an item)
Season:   (name of the season)
Taste:    (1 taste or several)
Funktion: (1 or several option)
Weight:   (1 or several)
Volume:   (1 volume or several)
Tips:     (for comments)
Flavor combinations: (1 or several)
Matching flavors: (several)

Please any suggestions regarding both the database design search queries for MySql.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

肤浅与狂妄 2025-01-09 03:10:34

一个简单的“一对多”应该可以工作:

在此处输入图像描述

您通过将 ITEM 与每个“连接”进行搜索儿童”桌子。


如果您希望限制属性值,您可以执行“真正的”多对多:

在此处输入图像描述

因此,一个项目不能与 TASTE 表中尚未存在的口味相关联(对于其他类型的属性等)。


或者您甚至可以创建一个通用模型,这样您就不会局限于任何特定的属性集:

https://i.sstatic.net/HpYOw.png" alt="在此处输入图像描述">

A simple "one-to-many" should work:

enter image description here

You search by JOINing ITEM with each of the "child" tables.


If you wish to limit the attribute values, you can do a "real" many-to-many:

enter image description here

So, an item cannot be associated with a taste that is not already in the TASTE table (etc. for other kinds of attributes).


Or you could even make a generalized model, so you are not limited to any particular set of attributes:

enter image description here

Caveat: this is very flexible and you now need to JOIN with just one table, but consistency is harder to enforce and may be necessary to do at the application level.

今天小雨转甜 2025-01-09 03:10:34

多值属性的标准设计是一个多对多表 - 这通常由一个复合主键组成,该主键由两个外键组成 - 每个连接表一个。

对这些的查询将涉及这个多对多表。

The standard design for multi valued attributes is a many-to-many table - this would normally consist of a compound primary key consisting of two foreign keys - one for each of the join tables.

The query on these would involve this many-to-many table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文