MySQL - How to DROP Foreign Key CONSTRAINTS



1.Using SQL

In MySQL you can DROP the Foreign Key constraints from a table by executing the next query:

ALTER TABLE `table`
DROP FOREIGN KEY `id_name_fk`;

If you want to disable the foreign keys just temporary, you can use the next query:

To disable

 SET FOREIGN_KEY_CHECKS=0;

To enable

 SET FOREIGN_KEY_CHECKS=1;

If you want to execute the DROP CONSTRAINT in MySQL, you have to also drop the indexes.

ALTER TABLE `table`
DROP FOREIGN KEY `id_name_fk`;

2.Using DbSchema

In DbSchema, you can drop the constraints straight from the diagram.

  1. Open the tables in the layout;

  2. Right-click on the foreign key;

  3. Select Drop.

dbschema drop contraints

Share this blog post on Twitter, Facebook, and LinkedIn