所以我有3個表:共享主鍵的多個表
口袋妖怪:
+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| National_ID | int(11) | NO | PRI | NULL | |
| Picture | longblob | YES | | NULL | |
| Name | varchar(15) | NO | | NULL | |
| Generation_ID | int(11) | NO | | NULL | |
| Type1 | varchar(8) | NO | | NULL | |
| Type2 | varchar(8) | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+
統計:
+-----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+-------+
| National_ID | int(11) | NO | PRI | NULL | |
| Health_Points | int(11) | NO | | NULL | |
| Attack | int(11) | NO | | NULL | |
| Defense | int(11) | NO | | NULL | |
| Special_Attack | int(11) | NO | | NULL | |
| Special_Defense | int(11) | NO | | NULL | |
| Speed | int(11) | NO | | NULL | |
| Ability1 | varchar(20) | NO | | NULL | |
| Ability2 | varchar(20) | YES | | NULL | |
+-----------------+-------------+------+-----+---------+-------+
其他:
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| National_ID | int(11) | NO | PRI | NULL | |
| Evolves_From | varchar(15) | YES | | NULL | |
| Species | varchar(20) | NO | | NULL | |
| Height_inch | int(11) | NO | | NULL | |
| Weight_lbs | int(11) | NO | | NULL | |
| Capture_Rate | int(11) | NO | | NULL | |
+--------------+-------------+------+-----+---------+-------+
我的問題是, Stats表中的National_ID指向th e口袋妖怪表中的National_ID,但我無法對雜項表做同樣的處理。
每當我嘗試在Misc中添加一個外鍵指向口袋妖怪表時,我得到一個重複錯誤。請幫助!謝謝
雜項表是否有任何外鍵約束? –
不,在此查詢之後「ALTER TABLE Misc ADD CONSTRAINT FK_National_ID FOREIGN KEY(National_ID)REFERENCES Pokemon(National_ID);」我會收到重複錯誤。 –
請指定您希望表格如何相互關聯。忘記「外鍵」等等。只是解釋你希望表格如何相互關聯。使用當前列將是有用的 –