简体   繁体   English

关系数据库中的自定义类型系统

[英]Custom type system in relational database

For an application we capture certain form data. 对于应用程序,我们捕获某些表单数据。 The user can include the various sections at will. 用户可以随意包含各个部分。

The kind of data that needs to be captured in each section is custom per section. 每个部分中需要捕获的数据类型是每个部分自定义的。 Sometimes they are simple dictionaries of key-value pairs. 有时它们是键值对的简单字典。 Sometimes they contain sub-components with one-to-many or many-to-many relationships. 有时它们包含具有一对多或多对多关系的子组件。 Though the number of sections may grow, for each section a schema would be known. 尽管部分的数量可能会增加,但是对于每个部分,架构都是已知的。

In the past, the form sections were fixed and so we could just hard-code the table structures for each section. 过去,表单节是固定的,因此我们只需对每个节的表结构进行硬编码即可。 We do not have a generic way to implement sections - it's new data access and tables for each new section. 我们没有通用的方式来实现节-它是新的数据访问和每个新节的表。

BUT, a new requirements says that the user should be able to design their OWN sections. 但是,一项新的要求说,用户应该能够设计自己的OWN部分。 To avoid dynamically manipulating database tables, we'd like to migrate to a higher-order schema that can express these sections in data. 为了避免动态操作数据库表,我们希望迁移到可以在数据中表达这些部分的高阶模式。

If the data were just key-value pairs of single valued fields, this could be implemented with a Sections table and a SectionFields table. 如果数据只是单值字段的键值对,则可以使用Sections表和SectionFields表来实现。 But because of the possibility of nesting through multiple-valued fields and fields of complex type, I believe we should approach this as a rudimentary type system. 但是由于有可能嵌套在多值字段和复杂类型的字段中,因此我认为我们应该将此作为基本类型系统。 I don't think it needs inheritance. 我认为它不需要继承。

Rather than reinvent this from scratch, I assume that work has been done in schemas for efficient type systems stored in the database. 我假设不是从头开始重新发明它,而是假设已经针对数据库中存储的高效类型系统在架构中完成了工作。 Any thoughts/guidance? 有什么想法/指导吗?

Thanks. 谢谢。

If the user is allowed to create their own data types, then the database that stores them is no longer a relational database. 如果允许用户创建自己的数据类型,则存储它们的数据库将不再是关系数据库。 Attempting to store this data in a traditional manner is going to be chaos. 尝试以传统方式存储此数据将是混乱的。

You should consider storing this data as XML snippits. 您应该考虑将此数据存储为XML代码段。 If you can build an XML schema that can support the users' selections, and if your database supports an XML datatype (as newer versions of SQL Server do), then you may still be able to do some useful queries on the data. 如果您可以构建一个可以支持用户选择的XML模式,并且您的数据库支持XML数据类型(如SQL Server的较新版本),那么您仍然可以对数据进行一些有用的查询。

Jason, 杰森,

I'm not sure I understand your question. 我不确定我是否理解您的问题。 This is a summary of what I've gleaned from reading it over: 这是我从阅读中学到的总结:

You capture form data for an application. 您捕获应用程序的表单数据。 Your requirements have changed to allow for user defined sections. 您的要求已更改为允许用户定义的部分。 This is a headache for you because in a relational database you'd have to dynamically alter the tables to accommodate this new requirement. 这让您很头疼,因为在关系数据库中,您必须动态更改表以适应此新要求。

This might be the case where you are using the wrong tool for the job. 在您使用错误的工具进行工作时,可能会出现这种情况。 Relational databases are great for storing and retrieving data with well-established relationships, but are kind of terrible when you have loosely-coupled or undefined relationships in the data. 关系数据库非常适合用于存储和检索具有良好关系的数据,但是当您在数据中具有松散耦合的关系或未定义的关系时,关系数据库会很糟糕。 You might find that you're better off with a technology like XML, which handles storage for loosely coupled data sets much better. 您可能会发现,使用XML之类的技术会更好,该技术可以更好地处理松散耦合的数据集的存储。

Sorry if this is not what you were looking for. 抱歉,这不是您想要的。 This is my first answer post on StackOverflow so I'm still getting the hang of this. 这是我在StackOverflow上的第一个答案,所以我仍然对此感到困惑。

Best of luck, 祝你好运

Michael 迈克尔

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

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