1

drop all tables;

or drop all tables from database;

GMB
  • 216,147
  • 25
  • 84
  • 135
  • 1
    This seems to be discussed in detail here: https://stackoverflow.com/questions/1690404/how-to-drop-all-user-tables – MandyShaw Feb 09 '19 at 16:38

2 Answers2

0

One way to do this would be to generate all the DDL statements using the metadata table

select 'DROP TABLE '||table_name||';'
  from user_tables

Run the query and copy-paste the output which would contains the statements for dropping tables

George Joseph
  • 5,842
  • 10
  • 24
  • Unless we use `cascade constraints` we need to drop tables in dependency order. A random order will probably result in ORA-02449 exceptions. – APC Feb 10 '19 at 09:02
0

One solution would be to DROP the user that owns the objects with the CASCADE option.

DROP USER myuser CASCADE;

This will efficiently drop all user objects (tables, views, packages, procedures, ...). You will then need to recreate the user.


Else, if you want to limit the scope of your action to just dropping all of your tables (and associated constraints), you could write a procedure that dynamically generates and executes a series of DROP TABLE statements :

BEGIN
   FOR cur_rec IN (SELECT object_name FROM user_objects WHERE object_type = 'TABLE')
   LOOP
      BEGIN
         EXECUTE IMMEDIATE 'DROP TABLE "' || cur_rec.object_name || '" CASCADE CONSTRAINTS';
      EXCEPTION
         WHEN OTHERS THEN
            DBMS_OUTPUT.put_line ('FAILED: DROP TABLE "' || cur_rec.object_name || '"');
      END;
   END LOOP;
END;
/
GMB
  • 216,147
  • 25
  • 84
  • 135