我創建了具有外鍵如下表:我怎麼看到它確實是一個外鍵和父表?
CREATE TABLE interests
(
int_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
an_interest VARCHAR(50) NOT NULL,
contact_id INT NOT NULL,
CONSTRAINT my_contacts_contact_id_fk
FOREIGN KEY (contact_id)
REFERENCES my_contacts (contact_id)
);
當我做DESC
我看到:
mysql> desc interests;
+------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+----------------+
| int_id | int(11) | NO | PRI | NULL | auto_increment |
| interest | varchar(50) | NO | | NULL | |
| contact_id | int(11) | NO | MUL | NULL | |
+------------+-------------+------+-----+---------+----------------+
3 rows in set (0.02 sec)
我知道什麼MUL
是,但我怎麼會明確地看到,contact_id
是定義爲外鍵,哪個是通過CLI的父表?
另外爲什麼我不能使用my_contacts_contact_id_fk
來刪除外鍵約束?
UPDATE
mysql> ALTER TABLE interests DROP CONSTRAINT my_contacts_contact_id_fk;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use n
ear 'CONSTRAINT my_contacts_contact_id_fk' at line 2
mysql>
你的表名是利益或my_interests? – 2013-04-06 12:09:48
@MoyedAnsari:Sorry.Copy-paste problem.Fixed OP – Cratylus 2013-04-06 12:14:48
'SHOW CREATE TABLE interests;' – Travesty3 2013-04-06 12:17:20