How to drop foreign key in mysql?
I've tried both syntaxes:
Alter Table bc DROP FOREIGN KEY STUD_ID;
It gives an error: cannot DROP 'STUD_ID'; make sure the column / key exists
Alter Table bc DROP CONSTRAINT STUD_ID;
It throws an error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual corresponding to your MySQL server version for the correct syntax to use next to "CONSTRAINT STUD_ID" on line 1
Suggest possible ways for me.
+3
source to share
3 answers
Your first request works. This tells you that no such key exists. This means that your key has a different name. It does not have the same name as the index that it is indexing. Execute
show index from bc
to show all the key names and then run the query again with the correct name
Alter Table bc DROP FOREIGN KEY <STUD_ID_index_name>
0
source to share