无架构 SQL 数据库表 - 实用的折衷方案

发布于 2024-09-12 07:29:57 字数 863 浏览 4 评论 0原文

这个问题试图找到这个问题的实用解决方案< /a>.

我需要为我的 SQL 数据库进行半无模式设计。但是,我可以限制灵活性,将其硬塞到整个 SQL 范例中。将来可能会选择迁移到无模式数据库,但现在我仍坚持使用 SQL。

我在 SQL 数据库中有一个表(我们称之为 Foo)。当向其中添加一行时,它需要能够存储任意数量的“元”字段。一个例子是能够附加任意元数据,如标签、协作者等。所有字段都是可选的,但问题是它们的类型不同。有些可能是数字,有些可能是文本等。

一个简单的设计将 Foo 链接到 OptionalValues 表,其中包含 name等字段value_typevalue_stringvalue_intvalue_date 等看起来很直接,尽管它下降到整个 EAV 模型,它看起来相当浪费。另外,我想当它增长时,查询会非常慢。不过,我不希望按此表中的任何内容进行搜索或排序。我所需要的是,当我从 Foo 中获取一行时,这些额外的属性也应该是可以获得的。

在 SQL 数据库中是否有实现此类设置的最佳实践,或者我只是错误地看待整个事情?

This question is an attempt to find a practical solution for this question.

I need a semi-schema less design for my SQL database. However, I can limit the flexibility to shoehorn it into the entire SQL paradigm. Moving to schema less databases might be an option in the future but right now, I' stuck with SQL.

I have a table in a SQL database (let's call it Foo). When an row is added to this, it needs to be able to store an arbitrary number of "meta" fields with this. An example would be the ability to attach arbitrary metadata like tags, collaborators etc. All the fields are optional but the problem is that they're of different types. Some might be numeric, some might be textual etc.

A simple design linking Foo to a table of OptionalValues with fields like name, value_type, value_string, value_int, value_date etc. seems direct although it descends into the whole EAV model which Alex mentions on that last answer and it looks quite wasteful. Also, I imagine queries out of this when it grows will be quite slow. I don't expect to search or sort by anything in this table though. All I need is that when I get a row out of Foo, these extra attributes should be obtainable as well.

Are there any best practices for implementing this kind of a setup in a SQL database or am I simply looking at the whole thing wrongly?

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

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

发布评论

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

评论(1

Bonjour°[大白 2024-09-19 07:29:57

将字符串列“Metafields”添加到表“Foo”中,并将元数据作为 XML 或 JSON 字符串存储在那里。

Add a string column "Metafields" to your table "Foo" and store your metadata there as an XML or JSON string.

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