Adam Bien's Weblog

Tuesday Dec 16, 2008

Generating DROP TABLES for ORACLE - One Statement

I forget it over and over again, now its here archived :-). The following statement generates DROP TABLE statements which really cleanup the Oracle database:

select 'drop table '||table_name||' CASCADE CONSTRAINTS;' from USER_TABLES

It is very useful for development (JPA will generate the tables for you again), and production (speeds up the performance) :-).

Nice thing: USER_TABLES and Oracle's dictionary is conceptually similar to reflection in Java.



*NEW* Workshop: "Real World Java EE 6/7 Bootstrap" and book: Real World Java EE Night Hacks--Dissecting the Business Tier

Comments:

Well performance decreases a little bit while doing this as user SYSTEM - so take care ;-)

Posted by Dirk on December 16, 2008 at 01:51 PM CET #

In MySQL, this is much easier:

DROP DATABASE xyz; CREATE DATABASE xyz

Posted by Michael Kuhlmann on December 18, 2008 at 11:06 AM CET #

Manual trackback: same query for dropping sequences.
Cheers :-).

Posted by Baptiste on December 22, 2008 at 09:38 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
Meta
My Recent Book
Java One 2009/2011
...the last 150 posts
...the last 10 comments
Links
License