How to drop all constraints in Mysql? in Cool Topics of MySQL
8215 Views
Example
-- [copy_table_name] is any name
-- [table_name] which table do you want to remove all constraints
CREATE TABLE [copy_table_name] (SELECT * FROM [table_name]);
SET foreign_key_checks = 0;
DROP TABLE [table_name];
SET foreign_key_checks = 1;
ALTER TABLE [copy_table_name] RENAME [table_name];
Five Steps to Drop all constrains in Mysql
1. Copy to another table.
2. Set foreign_key_checks false.
3. Remove existing table.
4. Set back foreign_key_check true.
5. Do rename of copy table.