【发布时间】:2012-02-28 14:14:46
【问题描述】:
我正在尝试从引用指定表的表中删除外键。我不知道外键的名称,我只知道它所在的表和它引用的表。这是我到目前为止得到的:
alter table tblTableWhereFKIs drop foreign key (select constraint_name
from information_schema.key_column_usage
where referenced_table_name = 'tblReferencedByFK' and table_name = 'tblTableWhereFKIs' limit 1);
但我得到一个错误:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(select constraint_name
from information_schema.key_column_usage
where referen' at line 1
选择单独起作用:
mysql> select constraint_name
-> from information_schema.key_column_usage
-> where referenced_table_name = 'tblReferencedByFK' and table_name = 'tblTableWhereFKIs' limit 1;
+-----------------------------------------+
| constraint_name |
+-----------------------------------------+
| fk_tblTableWhereFKIs_tblReferencedByFK1 |
+-----------------------------------------+
1 row in set (0.08 sec)
【问题讨论】: