我需要从我的MySQL数据库中删除一个不推荐使用的空表。
表的定义是noddy:
CREATE TABLE IF NOT EXISTS `Address` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`ContactId` int(11) NOT NULL,
PRIMARY KEY (`Id`),
KEY `ContactId` (`ContactId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;这会导致
#1217 - Cannot delete or update a parent row: a foreign key constraint fails
在ContactId上有一个限制,但我已经删除了它。
PHPMyAdmin的export函数不会显示上面所示的表定义以外的任何内容。表中没有行,据我所知,没有FK引用Address.Id字段(但我不知道如何验证这一点)。
有人能告诉我怎样才能摆脱这张桌子吗?
发布于 2011-11-18 21:11:13
列出外键
select
concat(table_name, '.', column_name) as 'foreign key',
concat(referenced_table_name, '.', referenced_column_name) as 'references'
from
information_schema.key_column_usage
where
referenced_table_name is not null;对于您的案例中的特定搜索:
select
constraint_name
from
information_schema.key_column_usage
where
referenced_table_name = 'Address' AND referenced_column_name = 'ContactId';要删除外键约束,请执行以下操作:
ALTER TABLE [table_name] DROP FOREIGN KEY [constraint_name];发布于 2011-11-18 21:07:48
SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE Address;
SET FOREIGN_KEY_CHECKS = 1;https://stackoverflow.com/questions/8182871
复制相似问题