MySQL deletes a foreign key column

Source: Internet
Author: User

Today, I encountered a problem about deleting a foreign key column. I found that:

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 |

At the beginning, I thought: Are you sure you want to delete the key first, then the constraint, and finally the column? Because the foreign key columns of MySQL are different from those of Oracle, MySQL has keys. After trying for a long time, MySQL failed to delete the foreign key columns. It was surprisingly simple:

alter table userfans drop foreign key FKF025E60B81E8743E;

Display:

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

It's really a waste of effort to break the shoes!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.