mysql中的外來鍵
Foreign keys definitions are subject to the following conditions:
Both tables must be
InnoDB
tables and they must not beTEMPORARY
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
andTEXT
columns cannot be included in a foreign key, because indexes on those columns must always include a prefix length.If the
CONSTRAINT
clause is given, thesymbol
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部落格 ” ,連結:http://blog.itpub.net/7425608/viewspace-921062/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MYSQL的外來鍵MySql
- mysql建立外來鍵語句MySql
- 如何在MySQL資料庫中定義外來鍵ZMMySql資料庫
- 教你mysql如何增加外來鍵約束MySql
- mysql 使用foreign key(外來鍵)MySql
- MySQL禁用恢復外來鍵約束MySql
- 在MySQL中利用外來鍵實現級聯刪除(轉)MySql
- mysql 刪除老是報外來鍵約束MySql
- Oracle外來鍵約束中NULL的處理OracleNull
- sqlserver外來鍵SQLServer
- MySQL新增外來鍵失敗ERROR 1452的解決MySqlError
- 父表修改與外來鍵的關係(主鍵DML與外來鍵的關係)
- Mysql truncate table時解決外來鍵關聯MySql
- mysql不能新增外來鍵約束怎麼辦MySql
- MySQL 用隨機資料填充外來鍵表MySql隨機
- mysql啟動和關閉外來鍵約束MySql
- SQL SERVER中找出拙劣的約束,索引,外來鍵SQLServer索引
- indexedDB 內鍵與外來鍵Index
- Mysql 外來鍵(FOREIGN KEY)使用注意事項MySql
- SQL的主鍵和外來鍵約束SQL
- 外來鍵技術
- 新的主鍵和外來鍵的語法
- 資料庫中沒有外來鍵的9個理由資料庫
- [轉] mysql 外來鍵(Foreign Key)的詳解和例項MySql
- MySQL·捉蟲動態·DROPDATABASE外來鍵約束的GTIDBUGMySqlDatabaseTiDB
- MySQL之外來鍵MySql
- 【實驗】【外來鍵】小議外來鍵約束對應用程式的影響
- MySQL 建立外來鍵報錯Can't write; duplicate key in tableMySql
- mysql資料庫匯入外來鍵約束問題MySql資料庫
- mysql~資料完整性考慮~外來鍵約束MySql
- mysql 外來鍵索引入門介紹,為什麼工作中很少有人使用?MySql索引
- oracle外來鍵約束的總結Oracle
- 查詢沒有索引的外來鍵索引
- 查詢一個表的外來鍵
- Oracle 外來鍵的級聯處理Oracle
- Oracle根據主鍵查詢外來鍵Oracle
- django外來鍵如何賦值Django賦值
- Oracle 外來鍵查詢sqlOracleSQL