Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to delete foreign key columns in MySQL

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article is to share with you about how to delete foreign key columns in MySQL, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Sql code

Show create table userfans

Java code

| | 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 first I thought: should I delete KEY first, then delete constraint, and finally delete columns? Because the foreign key columns of MySQL are different from those of MySQL, they all have KEY. As a result, I tried and failed for a long time, and finally found that deleting the foreign key column was surprisingly simple:

Sql code

Alter table userfans drop foreign key FKF025E60B81E8743E

Display:

Sql code

Query OK, 2 rows affected (0.32 sec)

Records: 2 Duplicates: 0 Warnings: 0

The above is how to delete the foreign key column in MySQL. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report