mysql删除外键

/*删除表前,查询某个表所有关联的外检,然后获取删除sql语句执行*/
select
TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME, CONCAT('alter table ',TABLE_NAME,' drop foreign key ',CONSTRAINT_NAME,';') DELETESQL
from INFORMATION_SCHEMA.KEY_COLUMN_USAGE
where
REFERENCED_TABLE_NAME = 't_s_role';

posted @ 2020-12-21 10:57  tuanz  阅读(250)  评论(0编辑  收藏  举报