存储子类别唯一属性的关系数据库结构

发布于 2024-11-08 15:26:45 字数 774 浏览 0 评论 0 原文

我正在创建一个可以是不同类型的结构的数据库。每种类型都有一组独特的属性,例如与结构类型具体相关的材料、形状、属性。

例如,一个结构是一座桥梁,它可以具有跨度长度和桥面材料类型。

结构的另一个例子是具有高度、材料类型和厚度的墙。

我不想生成包含所有可能属性的平面表,因为可能存在多种类型的结构,并且属性很灵活,并且有许多属性要存储。

基本上,我们希望通过将独特的属性数据存储在每种结构类型的单独表中来防止记录变得太大,但我想不出一种方法来链接通用结构表以轻松指向属性表。

=================== 编辑,

现在搜索“泛化专业化关系建模”,看来我想将数据建模为面向对象的结构,其父类“结构”具有继承公共信息(如桥结构、墙结构)的子类。现在唯一的问题是,我正在尝试帮助工程师制作一个简单的独立 Access 2010 数据库,但看来我正在正确生成 access 中的关系,父类的主键是子类的主键和外键类。这似乎会导致 Access 2010 内部出现问题,它希望父类的实例包含每个子类之一,这是无意义的。

基本上,我将

StructureID 作为结构、桥和墙表上的主键,桥和墙表上的主键是 StructureID 链接回结构表。我对 Access 2010 不太熟悉,不知道为什么它不起作用。

来自 IBM 论文之一,

基本上想要在 Access 2010 中进行此操作。

I am creating a database of structures that can be of different types. Each of the types has a set of unique attributes such as the materials, shape, properties related specifically to the type of structure.

For instance, a structure is a bridge which can have a span length and material type for the deck.

Another instance of a structure would be a wall which has a height and material type and thickness.

I do not want to generate a flat table that contains all possible attributes as there are many types of structures that could exist and the attributes are flexible and there are numerous attributes to store.

Basically we want to prevent records from getting too large by storing unique attribute data in a separate table for each type of structure but I can't think of a way to link the generic structure table to point to the attribute tables easily.

====================
EDIT,

Now that searched for "generalization specialization relational modeling" it appears that I want to model the data as a object oriented structure with a parent class "structure" that has child classes that inherit the common information as bridge structure, wall structure. The only issue now is that I am trying to help a engineer make a simple stand alone Access 2010 database but it appears that I am correctly generating the relationships within access with the primary key of the parent class being the primary and foreign key of the child classes. This appears to cause an issue inside Access 2010 where it wants instances of the parent to contain one of each child class which is non-sense.

Basically I have,

StructureID as the primary key on both structure, bridge, and wall tables on the bridge and wall table their primary key which is the structureID links back to the structure table. I am not too familiar with Access 2010 and don't know why it doesnt work.

From one of the IBM papers,

"Figure 8. Mapping all classes of the extended hierarchy to data entities"

Basically want to make this in an Access 2010.

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

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

发布评论

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

评论(3

不乱于心 2024-11-15 15:26:45

我建议尝试尽可能地将结构拆分为单独的表。
您还可以拥有一个包含所有结构及其公共属性的主表。

另一种方法是使用 xml 类型列,它可以像任何 xml 一样灵活,或者您可以应用架构来强制数据完整性。

您基本上需要在这两个选项之间进行平衡。

数据库设计还取决于您的 DBMS 功能。例如,并非所有数据库都支持 XML 类型。

[编辑]

表结构可能如下所示:

结构

  • Id - 自动生成的 PK
  • 名称
  • 类型
  • 颜色

  • Id
  • StructreId 引用 Structure(Id)
  • 长度
  • MaterialType

墙壁

  • Id
  • StructreId 引用 Structure(Id)
  • 高度
  • 厚度
  • MaterialType

I suggest trying to split the structures into separate tables as much as you can.
You can also have a master table with all the structures and their common properties.

Another approach is to have xml type column, which can be as flexible as any xml or you can apply schema to enforce data integrity.

You basically need to balance between those two options.

Database design also depends on your DBMS capabilities. For example, not all databases support XML types.

[Edit]

The table structure could be like this:

Structure

  • Id - auto-generated PK
  • Name
  • Type
  • Color

Bridge

  • Id
  • StructreId references Structure(Id)
  • Length
  • MaterialType

Wall

  • Id
  • StructreId references Structure(Id)
  • Height
  • Thikness
  • MaterialType
人间☆小暴躁 2024-11-15 15:26:45

您的案例看起来像是一代规格设计模式的一个实例。如何设计关系表来反映gen-spec的问题之前已经被提出过。

查看一个主题

Your case looks like an instance of the gen-spec design pattern. The question of how to design relational tables to reflect gen-spec has been brought up before.

See one thread.

扬花落满肩 2024-11-15 15:26:45

我认为您在 Access 中设置依赖项的方式可能犯了一个小错误。似乎您需要一对一或一对零或一。

I think you may have made a small error in the way you set up the dependancies in Access. Seems you have one-to-one where you need one-to-zero-or-one.

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