DROP all foreign keys in MYSQL database

前端 未结 4 1547
被撕碎了的回忆
被撕碎了的回忆 2020-12-24 01:33

Foreign keys are causing me too many problems modifying an database structure to meet new requirements - I want to modify primary keys but it seems I can\'t when foreign key

4条回答
  •  抹茶落季
    2020-12-24 02:26

    Run

    SELECT concat('ALTER TABLE ', TABLE_NAME, ' DROP FOREIGN KEY ', CONSTRAINT_NAME, ';') 
    FROM information_schema.key_column_usage 
    WHERE CONSTRAINT_SCHEMA = 'db_name' 
    AND referenced_table_name IS NOT NULL;
    

    and run the output.

提交回复
热议问题