Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2023-08-28 19:17:11
forward
1497 people have browsed it

我们如何从现有 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
Copy after login

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
Copy after login

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!

source:tutorialspoint.com
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!