We can remove FOREIGN KEY constraints from columns of existing tables by using DROP keyword and ALTER TABLE statement.
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.
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!