ITPub博客

首页 > 数据库 > MySQL > mysql中的外键

mysql中的外键

原创 MySQL 作者:realji 时间:2007-06-25 17:05:06 0 删除 编辑

Foreign keys definitions are subject to the following conditions:

  • Both tables must be InnoDB tables and they must not be TEMPORARY tables.

  • Corresponding columns in the foreign key and the referenced key must have similar internal data types inside InnoDB so that they can be compared without a type conversion. The size and sign of integer types must be the same. The length of string types need not be the same. For non-binary (character) string columns, the character set and collation must be the same.

  • In the referencing table, there must be an index where the foreign key columns are listed as the first columns in the same order. Such an index is created on the referencing table automatically if it does not exist.

  • In the referenced table, there must be an index where the referenced columns are listed as the first columns in the same order.

  • Index prefixes on foreign key columns are not supported. One consequence of this is that BLOB and TEXT columns cannot be included in a foreign key, because indexes on those columns must always include a prefix length.

  • If the CONSTRAINT symbol clause is given, the symbol value must be unique in the database. If the clause is not given, InnoDB creates the name automatically.

参照mysql中的说明,建外键时一定要注意2个表字段之间的关系,一定要一致,mysql中的数据类型相对要比oracle的多,我遇到了int ,unsigned的问题。1个表的id字段是int,令1个表的id字段是int,unsigned。结果建了很多次外键,都没成功,找了半天才看到。看来还是太粗心。。

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/7425608/viewspace-921062/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: vnc配置--摘
下一篇: mysqldump导出数据
请登录后发表评论 登录
全部评论

注册时间:2008-01-09

  • 博文量
    55
  • 访问量
    161930