18 Apr 2014
Mysql – disabling and enabling foreign key checks
Recently I was working on a project in which I have to truncate tables in database. But due to foreign key constraints MySQL was throwing errors.
So the solution I found was to disable Foreign Key constraints temporarily delete all data and then again enable the foreign keys.
Disable foreign key checks.
SET FOREIGN_KEY_CHECKS=0;
Enable foreign key checks.
SET FOREIGN_KEY_CHECKS=1;