0

I have created a table which has a foreign key as follows:

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)  
);  

When I do DESC I see:

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)  

I know what MUL is but how would I explicitely see that contact_id is defined as a foreign key and which is the parent table via CLI?
Also why can't I use my_contacts_contact_id_fk to drop the foreign key constraint?

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>
4

1 回答 1

0

约束本身就是数据库对象,所以当你运行时没有显示约束的完整描述并不让我感到惊讶 desc [interests]。试试desc [my_contacts_contact_id_fk]

您应该能够执行alter table [interests] drop constraint [my_contacts_contact_id_fk]. 如果您在删除时遇到问题,您可以发布您的更改表 SQL 和来自服务器的响应吗?

于 2013-04-06T12:20:21.063 回答