AltertableordersDROPFOREIGNKEYo"/> AltertableordersDROPFOREIGNKEYo">

Home  >  Article  >  Database  >  How can we remove FOREIGN KEY constraint from column of existing MySQL table?

How can we remove FOREIGN KEY constraint from column of existing MySQL table?

WBOY
WBOYforward
2023-08-28 19:17:111501browse

我们如何从现有 MySQL 表的列中删除 FOREIGN KEY 约束?

We can remove FOREIGN KEY constraints from columns of existing tables by using DROP keyword and ALTER TABLE statement.

grammar

ALTER TABLE table_name DROP FOREIGN KEY constraint_name

The constraint name here is the name of the foreign key constraint we applied when creating the table. If no constraint name is specified, MySQL will provide the constraint name, which can be checked via the SHOW CREATE TABLE statement.

Example

The following query will delete the FOREIGN KEY constraint from the "orders" table -

mysql> Alter table orders DROP FOREIGN KEY orders_ibfk_1;
Query OK, 0 rows affected (0.22 sec)
Records: 0 Duplicates: 0 Warnings: 0

The above is the detailed content of How can we remove FOREIGN KEY constraint from column of existing MySQL table?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete