Drop all foreign key constraints for a schema

I hates the FKs, my precious.

 

SELECT 
  CONCAT(
    'ALTER TABLE ',
    table_schema,
    '.',
    table_name,
    ' DROP FOREIGN KEY ',
    constraint_name,
    ';'
  ) 
FROM
  information_schema.table_constraints 
WHERE constraint_type = 'FOREIGN KEY' 
  AND table_schema LIKE 'schemaName' ;

Tags

Related Posts

Share This