Question

I have a databse called store having 100 tables having too much foreign key references with tables, having thousands of records.

Problem: Is it possible something like truncate to delete all the rows of all the tables in a single query.

I tried but I am not able to find the exact way to achieve this when I try to TRUNCATE TABLE it gives me error: Cannot delete or update a parent row: a foreign key constraint fails which is expected too.

Can anyone please help me to achieve this, or suggest me the better way to do this.

Was it helpful?

Solution

Do this before deleting:

SET FOREIGN_KEY_CHECKS=0;

When finished, reset it to 1:

SET FOREIGN_KEY_CHECKS=1;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top