How to truncate a MySQL table in spite of a foreign key

This can be done by disabling index checks.

Yes you can:

SET FOREIGN_KEY_CHECKS = 0;

TRUNCATE table1;

TRUNCATE table2;

SET FOREIGN_KEY_CHECKS = 1;

With these statements, you risk letting in rows into your tables that do not adhere to the FOREIGN KEY constraints. As per mysql documentation, TRUNCATE cannot be used on tables with foreign key relationships

Search Terms:

mysql truncate table in spite of foreign key

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top