Difference between revisions of "Oracle/Drop all user tables"

From YavInWiki
Jump to navigation Jump to search
m
Line 14: Line 14:
select 'drop '||object_type||' '||object_name||' cascade constraints;'
select 'drop '||object_type||' '||object_name||' cascade constraints;'
   from USER_OBJECTS
   from USER_OBJECTS
   where object_type = 'TABLE'
   --where object_type = 'TABLE'
   order by object_type, object_name;
   order by object_type, object_name;



Revision as of 08:57, 31 August 2010

-- 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;