Re: Remove everything from a schema

From: Michel Cadot <micadot{at}altern{dot}org>
Date: Thu, 27 Nov 2008 17:21:52 +0100
Message-ID: <492ec921$0$25687$>

"Charles Hooper" <> a écrit dans le message de news: On Nov 27, 7:33 am, "Álvaro G. Vicario"
<> wrote:
> I want to remove all the contents of a schema (tables, indexes,
> sequences...) in my development box so I can checkout a fresh working
> copy of the web site I'm working on and generate all objects from
> scratch. The server runs version in a separate network machine
> and I'd rather not ask the DBA to do it for me every time.
> What's the easiest way to do it?
> --
> -- Álvaro G. Vicario - Burgos, Spain

One method is to drop the user that owns the schema using the CASCADE option. You would then need to recreate the schema owner, which will be done automatically if you import the user schema using the imp utility. In the following, replace schema with the owner of the schema:

If you are not using imp to recreate the user, you will need to take additional steps to recreate user. I suggest querying DBA_USERS for the information related to the schema user. Make note of the password hash, default tablespace, etc. The password hash may be used to recreate the user with the same password "CREATE USER ______ IDENTIFIED BY VALUES ____"... Charles Hooper
IT Manager/Oracle DBA
K&M Machine-Fabricating, Inc.

In this case, you will also need to regrant all privileges. I use the following script to drop all my objects:

set heading off
set pagesize 0
set feedback off
set timing off
set time off
set trimspool on
set trimout on
set linesize 100
set echo off
spool t
select 'drop '||object_type||' '||object_name||

       decode(object_type,'CLUSTER',' including tables cascade constraints',
                          'OPERATOR', ' force',
                          'TABLE',' cascade constraints',
                          'TYPE', ' force',
                          'VIEW',' cascade constraints',

from user_objects
where object_type in ('CLUSTER', 'CONTEXT', 'DATABASE LINK', 'DIMENSION',
                      'DIRECTORY', 'FUNCTION', 'INDEX TYPE', 'JAVA',
                      'LIBRARY', 'MATERIALIZED VIEW', 'OPERATOR',
                      'OUTLINE', 'PACKAGE', 'PROCEDURE', 'SEQUENCE',
                      'SYNONYM', 'TABLE', 'TYPE', 'VIEW')
order by object_type, object_name
spool off
purge recyclebin;

Michel Received on Thu Nov 27 2008 - 10:21:52 CST

Original text of this message