【问题标题】:mysql adding constraints to compound primary keymysql向复合主键添加约束
【发布时间】:2015-10-09 18:28:37
【问题描述】:

这实际上是一个名为 catalog_product_index_price_bundle_idx 的 magento 1.4 表,在 3 个字段上有一个主键,但我的问题是对 mysql 实践的通用:

  • entity_id
  • customer_group_id
  • website_id

此版本中的所有表都是 innoDB,并且大多数表都有约束(通常在 DELETE CASCADE 上)返回到其他地方的正确主键。

但是,这张表不同;没有限制,entity_id 肯定会回到catalog_product_entity.entity_id

简单的问题,您如何将约束添加到主键的小数部分?这有什么问题或我需要注意的事情吗?

【问题讨论】:

    标签: mysql magento constraints innodb referential-integrity


    【解决方案1】:

    肯定可以http://sqlfiddle.com/#!9/3eea9/2

    唯一的问题是外键需要列在某个索引中是 first,如 t3.b 所示 - 但 MySQL 会自动为您创建这样的索引

    【讨论】:

      猜你喜欢
      • 2015-06-23
      • 2014-06-01
      • 2019-11-11
      • 1970-01-01
      • 1970-01-01
      • 2013-10-06
      • 2011-07-12
      • 2011-01-23
      • 2013-03-10
      相关资源
      最近更新 更多