You can delete without knowing the name by creating a concatenation request and executing automatically:
set @s:=''; select @s:=concat(@s, 'alter table ', 'your_table', ' drop foreign key ',CONSTRAINT_NAME, ';') from information_schema.key_column_usage where CONSTRAINT_SCHEMA = 'your_database' and TABLE_NAME ='your_table' and REFERENCED_TABLE_NAME = 'the_foreign_reference_table'; prepare stmt from @s; execute stmt; deallocate prepare stmt;
In this case, you do not need to know the name of the foreign key, you only need the name of the table for which you want to delete the foreign key, the database name and the reference table.
jose miguel rivera rodríguez
source share