我不想手动删除所有的目录,有办法删除数据库中的所有外键约束吗?
可以使用此SQL生成ALTERTABLE:
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=’!!YOUR_SCHEMA_HERE!!’;
它将输出这样的SQL:
alter table viewpoint_test.answer_code DROP FOREIGN KEY
fk_answer_code_codebook_item1; alter table viewpoint_test.answer_code DROP
FOREIGN KEY fk_answer_code_questionary_answer1; alter table
viewpoint_test.codebookDROP FOREIGN KEY codebook_ibfk_1;
热门工具 换一换