Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently using Liquibase for creating test data in my database before each test run.

I came across a problem where some of the test cases need special data, while others need the tables to be empty.

So I decided to give Liquibase contexts a try and only insert the data I really need for the current testcase plus - in an abstract superclass - all the data every test case needs (user accounts and stuff)...

I would like to clear the tables before each run, however I can't seem to find anything for this case except dropAll(), which seems to be overkill...

I'm not quite sure if it is even possible - because of foreign keys and other constraints - but I wonder if there is a way to delete the content of ALL the tables without dropping them completely?

share|improve this question
up vote 1 down vote accepted

I guess the fastest way would be to use a custom sql tag that uses truncate ... cascade on all "top-level" tables.

Using the cascade keyword for truncate will also (recursively) delete all rows from all dependent tables (all tables referencing the one that is being truncated).

Something like:

   truncate table parent_1, parent_2, foobar cascade;

Don't know if that is feasible with the number of tables you have or not.

share|improve this answer
Thanks for your reply :-) Since I don't know if it's feasible (and because "dropAll()" runs for at least 10min now without any visible success), I'll go talk to someone who's in charge (:P) and tell him about it ... :-) – gilaras Apr 3 '12 at 7:20
@gilaras: if a dropAll() takes that long, I would suspect some locking, e.g. transactions still referencing the tables that are to be dropped. If that is the case you would have the same problem with truncate. – a_horse_with_no_name Apr 3 '12 at 7:23
you're right, there was something wrong that made the dropAll() take so long; my IDE thought it would be funny to import a wrong package (long live auto-completion!) ... so there was a loop somewhere ... now that I told which package to import by hand, everything works ;-) Thanks! :) – gilaras Apr 3 '12 at 8:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.