I am attempting to write a MySQL statement to delete a foreign key constraint from a table, however I will not be provided the name for the constraint. I will be provided the table and column names, which I know I can then use by searching in the information_schema.KEY_COLUMN_USAGE table to retrieve the constraint name. Currently, I have the following statement, which is obviously incorrect, but I can't remember how I would accomplish what I want to do:
ALTER TABLE [table] DROP FOREIGN KEY (SELECT CONSTRAINT_NAME foreignKey FROM information_schema.KEY_COLUMN_USAGE WHERE CONSTRAINT_SCHEMA = DATABASE() AND TABLE_NAME = '[table]' AND COLUMN_NAME = '[column]' AND REFERENCED_TABLE_NAME IS NOT NULL LIMIT 1);