`

@Marked-MySQL删除外键列

阅读更多

今天遇到一个要删除外键列的问题,我发现:

show create table userfans;
| userfans | CREATE TABLE `userfans` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `status` int(11) DEFAULT NULL,
  `update_time` datetime DEFAULT NULL,
  `user` int(11) DEFAULT NULL,
  `fllower` int(11) DEFAULT NULL,
  `follower` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
KEY 'FKF025E60B81E8743E` (`fllower`),
  KEY `FKF025E60BAFF2360E` (`user`),
  KEY `FKF025E60BC1B86A61` (`follower`),
CONSTRAINT `FKF025E60B81E8743E` FOREIGN KEY(`fllower`) REFERENCES `user` (`id`),
  CONSTRAINT `FKF025E60BAFF2360E` FOREIGN KEY (`user`) REFERENCES `user` (`id`),
  CONSTRAINT `FKF025E60BC1B86A61` FOREIGN KEY (`follower`) REFERENCES `user` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 |

刚开始我想:是不是先删除KEY,再删除constraint,最后删除列?因为MySQL的外键列和Oracle不一样,MySQL的都是有KEY的;结果试了半天一直失败,最后发现,删除外键列竟然出奇的简单:

alter table userfans drop foreign key FKF025E60B81E8743E;

显示:

Query OK, 2 rows affected (0.32 sec)
Records: 2  Duplicates: 0  Warnings: 0

 真的是踏破铁鞋,白费功夫!

 

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics