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

From YavInWiki
Jump to navigation Jump to search
(New page: <source lang="oracle11"> select 'drop table '||table_name||' cascade constraints;' from user_tables; BEGIN for c in (select table_name from user_tables) loop execute immediate ('drop ...)
 
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
<source lang="oracle11">
<source lang="oracle11">
select 'drop table '||table_name||' cascade constraints;' from user_tables;
-- v1
select 'drop table '||table_name||' cascade constraints;'
  from user_tables;


-- v2
BEGIN
BEGIN
   for c in (select table_name from user_tables) loop
   for c in (select table_name from user_tables) loop
  execute immediate ('drop table '||c.table_name||' cascade constraints');
    execute immediate ('drop table '||c.table_name||' cascade constraints');
   end loop;
   end loop;
END;
END;
-- v3 (usable for other types too)
select 'drop '||object_type||' '||object_name||';'
  from USER_OBJECTS
  --where object_type = 'TABLE'
  order by object_type, object_name;
-- ... !!!
BEGIN
  for c in (SELECT object_type, object_name FROM USER_OBJECTS) loop
    execute immediate ('drop '||c.object_type||' '||c.object_name);
  end loop;
END;
-- remove BIN$* objects
purge RECYCLEBIN;
</source>
</source>


[[Category:Oracle]]
[[Category:Oracle]]

Latest revision as of 08:48, 1 September 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||';'
  from USER_OBJECTS
  --where object_type = 'TABLE'
  order by object_type, object_name;

-- ... !!!
BEGIN
  for c in (SELECT object_type, object_name FROM USER_OBJECTS) loop
    execute immediate ('drop '||c.object_type||' '||c.object_name);
  end loop;
END;

-- remove BIN$* objects
purge RECYCLEBIN;