-- 查询指定数据库外键
SELECT
CONSTRAINT_NAME AS '外键名称',
TABLE_NAME AS '表名',
COLUMN_NAME AS '列名',
REFERENCED_TABLE_NAME AS '参考表',
REFERENCED_COLUMN_NAME AS '参考列'
FROM
INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE
CONSTRAINT_SCHEMA = 'Plan' AND REFERENCED_TABLE_NAME IS NOT NULL;
-- 删除单个外键
ALTER TABLE PLR_GraphicProgressAttached DROP FOREIGN KEY RefPL_GraphicProgress232;
-- 获取删除指定库所有外键的脚本
SELECT CONCAT('ALTER TABLE ', table_name, ' DROP FOREIGN KEY ', constraint_name, ';')
FROM information_schema.key_column_usage
WHERE referenced_table_schema = 'Plan' AND referenced_table_name IS NOT NULL;
mysql 删除外键
最新推荐文章于 2024-04-28 17:24:38 发布