dbTalk Databases Forums  

Remove everything from a schema

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Remove everything from a schema in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Álvaro G. Vicario
 
Posts: n/a

Default Remove everything from a schema - 11-27-2008 , 06:33 AM






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 9.2.0.1.0 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?



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--

Reply With Quote
  #2  
Old   
Charles Hooper
 
Posts: n/a

Default Re: Remove everything from a schema - 11-27-2008 , 07:24 AM






On Nov 27, 7:33*am, "Álvaro G. Vicario"
<alvaroNOSPAMTHA... (AT) demogracia (DOT) com> wrote:
Quote:
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 9.2.0.1.0 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?

--
--http://alvaro.es- Á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:
DROP USER schema CASCADE;

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.


Reply With Quote
  #3  
Old   
Charles Hooper
 
Posts: n/a

Default Re: Remove everything from a schema - 11-27-2008 , 07:24 AM



On Nov 27, 7:33*am, "Álvaro G. Vicario"
<alvaroNOSPAMTHA... (AT) demogracia (DOT) com> wrote:
Quote:
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 9.2.0.1.0 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?

--
--http://alvaro.es- Á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:
DROP USER schema CASCADE;

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.


Reply With Quote
  #4  
Old   
Charles Hooper
 
Posts: n/a

Default Re: Remove everything from a schema - 11-27-2008 , 07:24 AM



On Nov 27, 7:33*am, "Álvaro G. Vicario"
<alvaroNOSPAMTHA... (AT) demogracia (DOT) com> wrote:
Quote:
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 9.2.0.1.0 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?

--
--http://alvaro.es- Á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:
DROP USER schema CASCADE;

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.


Reply With Quote
  #5  
Old   
Charles Hooper
 
Posts: n/a

Default Re: Remove everything from a schema - 11-27-2008 , 07:24 AM



On Nov 27, 7:33*am, "Álvaro G. Vicario"
<alvaroNOSPAMTHA... (AT) demogracia (DOT) com> wrote:
Quote:
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 9.2.0.1.0 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?

--
--http://alvaro.es- Á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:
DROP USER schema CASCADE;

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.


Reply With Quote
  #6  
Old   
Michel Cadot
 
Posts: n/a

Default Re: Remove everything from a schema - 11-27-2008 , 10:21 AM




"Charles Hooper" <hooperc2000 (AT) yahoo (DOT) com> a écrit dans le message de news:
d952204e-7625-48c6-b80a-0a19549e6f07...oglegroups.com...
On Nov 27, 7:33 am, "Álvaro G. Vicario"
<alvaroNOSPAMTHA... (AT) demogracia (DOT) com> wrote:
Quote:
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 9.2.0.1.0 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?

--
--http://alvaro.es- Á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:
DROP USER schema CASCADE;

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
@t.lst
purge recyclebin;

Regards
Michel






Reply With Quote
  #7  
Old   
Michel Cadot
 
Posts: n/a

Default Re: Remove everything from a schema - 11-27-2008 , 10:21 AM




"Charles Hooper" <hooperc2000 (AT) yahoo (DOT) com> a écrit dans le message de news:
d952204e-7625-48c6-b80a-0a19549e6f07...oglegroups.com...
On Nov 27, 7:33 am, "Álvaro G. Vicario"
<alvaroNOSPAMTHA... (AT) demogracia (DOT) com> wrote:
Quote:
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 9.2.0.1.0 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?

--
--http://alvaro.es- Á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:
DROP USER schema CASCADE;

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
@t.lst
purge recyclebin;

Regards
Michel






Reply With Quote
  #8  
Old   
Michel Cadot
 
Posts: n/a

Default Re: Remove everything from a schema - 11-27-2008 , 10:21 AM




"Charles Hooper" <hooperc2000 (AT) yahoo (DOT) com> a écrit dans le message de news:
d952204e-7625-48c6-b80a-0a19549e6f07...oglegroups.com...
On Nov 27, 7:33 am, "Álvaro G. Vicario"
<alvaroNOSPAMTHA... (AT) demogracia (DOT) com> wrote:
Quote:
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 9.2.0.1.0 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?

--
--http://alvaro.es- Á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:
DROP USER schema CASCADE;

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
@t.lst
purge recyclebin;

Regards
Michel






Reply With Quote
  #9  
Old   
Michel Cadot
 
Posts: n/a

Default Re: Remove everything from a schema - 11-27-2008 , 10:21 AM




"Charles Hooper" <hooperc2000 (AT) yahoo (DOT) com> a écrit dans le message de news:
d952204e-7625-48c6-b80a-0a19549e6f07...oglegroups.com...
On Nov 27, 7:33 am, "Álvaro G. Vicario"
<alvaroNOSPAMTHA... (AT) demogracia (DOT) com> wrote:
Quote:
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 9.2.0.1.0 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?

--
--http://alvaro.es- Á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:
DROP USER schema CASCADE;

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
@t.lst
purge recyclebin;

Regards
Michel






Reply With Quote
  #10  
Old   
Álvaro G. Vicario
 
Posts: n/a

Default Re: Remove everything from a schema - 11-28-2008 , 05:09 AM



Michel Cadot escribió:
Quote:
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
@t.lst
purge recyclebin;
This is not a complement to Charles' solution but an alternative, isn't
it? (Running "DROP USER schema CASCADE" would be an option but it
implies contacting the DBA.)

The production box will be using a bare Instant Client so I prefer not
to rely on SQL*Plus commands but I get the idea. I've run the commands
generated by your SELECT query and everything is happily gone. I can
easily stuff it in a PHP script (or just run it manually).

Thank you!


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.