Given a MariaDB table customer
, which other tables have a foreign key constraint on, I'm querying those table names with the following statement:
SELECT TABLE_NAME,
COLUMN_NAME,
CONSTRAINT_NAME,
REFERENCED_TABLE_NAME,
REFERENCED_COLUMN_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE REFERENCED_TABLE_NAME = 'customer';
Now, I'd like to delete the foreign keys in all tables from the above query but I don't know how to do that. The result shall be something like the following, where table_name
and constraint_name
are variables representing the result of the above query.
ALTER TABLE table_name DROP FOREIGN KEY constraint_name;