【问题标题】:Relationships between tables with options表与选项之间的关系
【发布时间】:2023-02-22 21:49:18
【问题描述】:

我为一家保险经纪公司创建了一组表,但我不相信关系系统。 这是 UML:

  • 保证级别可以有选项。
  • 报价与保证级别相关,也可以与相同保证级别的期权相关。

我的问题是我不知道如何强制链接到报价的选项必须链接到相同的保证级别。因为在这个方案中,链接到某个保证级别的报价可以链接到另一个级别的选项。 也许我的模式是错误的,应该添加或删除一些表。 我在我的项目中使用了一个 MySQL 数据库和 Doctrine ORM,所以模式应该与它兼容。

有没有人对模式有更好的想法?

【问题讨论】:

    标签: database-design


    【解决方案1】:

    您可以在 QuoteGuaranteeOption 表中包含 guarantee_level_id 列,并使其成为链接到 GuaranteelevelOptionQuote 表的外键的一部分。

    您的表定义将是这样的:

    create table QuoteGuaranteeOption (
      id int not null,
      quote_id int not null,
      guarantee_level_option_id int not null,
      guarantee_level_id int not null,
      --  other columns
      primary key (id),
      foreign key (guarantee_level_id, quote_id) references Quote (guarantee_level_id, id),
      foreign key (guarantee_level_id, guarantee_level_option_id) references GuaranteelevelOption (guarantee_level_id, id)
    )
    

    您将需要链接表中的相应索引才能定义这些 FK。

    这样您将只能链接相同保证级别的报价和选项。

    【讨论】:

      猜你喜欢
      • 2019-12-17
      • 1970-01-01
      • 1970-01-01
      • 2019-11-13
      • 2013-01-03
      • 2018-01-09
      • 2015-05-15
      • 1970-01-01
      相关资源
      最近更新 更多