MySQL – How to temporarily disable a foreign key constraint

To disable foreign key constraints when you want to truncate a table:

Use FOREIGN_KEY_CHECKS

SET FOREIGN_KEY_CHECKS=0;

and remember to enable it when you’re done:

SET FOREIGN_KEY_CHECKS=1;

admin

Writes about Web & Architecture at Pheonix Solutions.

Leave a Reply

Scroll to Top