Home > Database > Mysql Tutorial > MySQL删除外键列_MySQL

MySQL删除外键列_MySQL

WBOY
Release: 2016-06-01 13:44:50
Original
1187 people have browsed it

Mysql外键

bitsCN.com

今天遇到一个要删除外键列的问题,我发现:
Sql代码 
show create table userfans; 
Java代码 
| 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的;结果试了半天一直失败,最后发现,删除外键列竟然出奇的简单:
Sql代码 
alter table userfans drop foreign key FKF025E60B81E8743E 
 

显示:
Sql代码 
Query OK, 2 rows affected (0.32 sec) 
Records: 2  Duplicates: 0  Warnings: 0 
 真的是踏破铁鞋,白费功夫!

作者“绝尘”
 

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template