Oracle/Drop all user tables

From YavInWiki
Revision as of 08:57, 31 August 2010 by Andy (talk | contribs)
Jump to navigation Jump to search
-- v1
select 'drop table '||table_name||' cascade constraints;'
  from user_tables;

-- v2
BEGIN
  for c in (select table_name from user_tables) loop
    execute immediate ('drop table '||c.table_name||' cascade constraints');
  end loop;
END;

-- v3 (usable for other types too)
select 'drop '||object_type||' '||object_name||' cascade constraints;'
  from USER_OBJECTS
  where object_type = 'TABLE'
  order by object_type, object_name;