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>