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

From YavInWiki
Jump to navigation Jump to search
Line 1: Line 1:
<source lang="oracle11">
<source lang="oracle11">
-- v1
-- v1
select 'drop table '||table_name||' cascade constraints;' from user_tables;
select 'drop table '||table_name||' cascade constraints;'
  from user_tables;


-- v2
-- v2
Line 11: Line 12:


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


</source>
</source>


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

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;