共計(jì) 1364 個(gè)字符,預(yù)計(jì)需要花費(fèi) 4 分鐘才能閱讀完成。
自動(dòng)寫(xiě)代碼機(jī)器人,免費(fèi)開(kāi)通
本篇內(nèi)容介紹了“mysql 中的外鍵是什么”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓丸趣 TV 小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
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 中的說(shuō)明,建外鍵時(shí)一定要注意 2 個(gè)表字段之間的關(guān)系,一定要一致,mysql 中的數(shù)據(jù)類(lèi)型相對(duì)要比 oracle 的多,我遇到了 int,unsigned 的問(wèn)題。1 個(gè)表的 id 字段是 int,令 1 個(gè)表的 id 字段是 int,unsigned。結(jié)果建了很多次外鍵,都沒(méi)成功,找了半天才看到。看來(lái)還是太粗心。。
“mysql 中的外鍵是什么”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注丸趣 TV 網(wǎng)站,丸趣 TV 小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
向 AI 問(wèn)一下細(xì)節(jié)