Oracle - drop multiple table in a single query

vim picture vim · Nov 17, 2014 · Viewed 48.5k times · Source

I have fifty tables in a database, in that I need only six tables.

How can I delete remaining tables by one single query?

Answer

DirkNM picture DirkNM · Nov 17, 2014

You can generate a list of DROP TABLE commands with the query below:

SELECT 'DROP TABLE ' || table_name || ';' FROM user_tables;

After that you remove your six tables you want to keep and execute the other commands. Or you add a WHERE table_name NOT IN (...) clause to the query.

Hope it helps.