H2 - How to truncate all tables?

Filip picture Filip · Nov 20, 2014 · Viewed 12.9k times · Source

I assume there is a way of doing this from code, at least some good workaround.

Please consider that I do not want to delete all tables (I've seen this command), just to delete rows from them but to keep existing schema and all constraints.

Maybe I can somehow obtain the list of all tables from metadata and apply TRUNCATE command for each separately? But what about their relations and foreign keys?

Any Idea?

Answer

Julian Ladisch picture Julian Ladisch · Nov 20, 2014

You may do it this way: