成都网站建设设计

将想法与焦点和您一起共享

mysql中的外键是什么

本篇内容介绍了“MySQL中的外键是什么”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

创新互联专注于辽源企业网站建设,成都响应式网站建设公司,商城开发。辽源网站建设公司,为辽源等地区提供建站服务。全流程按需规划网站,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务

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。结果建了很多次外键,都没成功,找了半天才看到。看来还是太粗心。。

“mysql中的外键是什么”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!


新闻标题:mysql中的外键是什么
文章转载:http://chengdu.cdxwcx.cn/article/igcsoe.html