【问题标题】:Is it possible for a field that is part of a composite key to be a foreign key referencing a primary key in another table?作为复合键的一部分的字段是否有可能是引用另一个表中的主键的外键?
【发布时间】:2021-05-20 06:25:57
【问题描述】:

我正在尝试为数据库建模,我有两个表:Cell_Information 和 Cell_Stats 在 Cell_Information 中,Cell_ID 是主键。

在 Cell_Stats 中,Cell_ID 和 Timestamp 是一个复合主键。

Cell_Stats.Cell_ID 是否有可能既是外键又是复合键的一部分?

【问题讨论】:

  • 答案是“是”——您可以轻松尝试。
  • 如果您遇到问题,请向我们展示导致问题的具体 SQL。

标签: mysql sql database-design foreign-keys composite-primary-key


【解决方案1】:

[a specific column] 是否有可能既是外键又是复合键的一部分?

是的。

这很容易。如果您无法使其正常工作,请提出另一个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    • 2020-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多