mysql select drop_MYSQL:基于SELECT结果的ALTER TABLE DROP FOREIGN KEY

法和安
2023-12-01

我有以下

mysql命令来删除外键约束:

ALTER TABLE network_profile DROP FOREIGN KEY 'FK98875604AC3BAD33';

但我更愿意使用SELECT语句首先发现外键constraint_id并在ALTER TABLE命令中使用它,但是不成功.这可能吗?

尝试:

ALTER TABLE network_profile DROP FOREIGN KEY (SELECT constraint_name FROM information_schema.key_column_usage WHERE column_name = 'mt_check_list' AND table_schema = 'mydb');

还尝试过:

SELECT @constraint_name := constraint_name FROM information_schema.key_column_usage WHERE column_name = 'mt_check_list' AND table_schema = 'mydb';

ALTER TABLE network_profile DROP FOREIGN KEY @constraint_name;

请帮忙?

 类似资料: