0

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.

3
  • If you want to delete all data you can simply recreate the DB. Delete the database and run the create script again. Commented Apr 17, 2013 at 13:11
  • This may help you? stackoverflow.com/q/1912813/1983854 Commented Apr 17, 2013 at 13:13
  • Take a look at punkave.com/window/2009/05/27/… Commented Apr 17, 2013 at 13:14

1 Answer 1

1

Do this before deleting:

SET FOREIGN_KEY_CHECKS=0;

When finished, reset it to 1:

SET FOREIGN_KEY_CHECKS=1;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.