Hi Kevin,
Hi all, Over the years I've done this routine tasks hundreds
of times - drop all of the objects in a schema (in
development or test) and then re-import all of the objects
from the equivalent production database.
notwithstanding the replies from Bert and John, I'd seriously advise
against dropping ALL the objects in a schema prior to a refresh from
production. You specifically mention an import from production.
Here's my problem - I have a system where both test and production use
database links to connect to other databases, the test system to another
test database and the production one to another production database.
When you drop all your objects in test, you are dropping the database
link. On import, you will recreate it with the details of the production
database - your test database will now be accessing a production
database. This is not a good thing!
I have to admit that when I need a full refresh of a test database, I
use the following script in TOAD, connected as the user I'm about to
refresh (ie, not SYS or SYSTEM!), rather than trying to drop all
objects:
begin
FOR x IN (SELECT table_name FROM user_tables) loop
execute immediate 'drop table ' || x.table_name || ' cascade
constraints purge';
end loop;
end;
The above assumes 10g and above, if 9i or previous:
begin
FOR x IN (SELECT table_name FROM user_tables) loop
execute immediate 'drop table ' || x.table_name || ' cascade
constraints';
end loop;
end;
Once the tables (indexes, constraints and triggers) have been done, the
following will tidy up everything else, leaving only the database links:
begin
FOR x IN (SELECT object_type, object_name FROM user_objects
WHERE object_type NOT IN ('PACKAGE
BODY','UNDEFINED','DATABASE LINK')) loop
execute immediate 'drop ' || x.object_type || ' ' || x.object_name;
end loop;
end;
It's a SQL Cache killer, but I'm about to kill it with the import
anyway! UNDEFINED in the above is a catcher for MAT VIEWS in older 9i
(or 8i) versions - when they switched from SNAPSHOTS to MVIEWS. The
object_type was set to UNDEFINED. The following then drops those, if
required:
begin
FOR x IN (SELECT object_type, object_name FROM user_objects
WHERE object_type = 'UNDEFINED') loop
execute immediate 'drop snapshot ' || x.object_name;
end loop;
end;
You are now left with a pristine test schema ready to import a full copy
of production, except for any database links which will remain as they
were and will still be pointing/connecting to a test database.
Cheers,
Norm. [TeamT]
Norman Dunbar
Contract Oracle DBA
CIS Engineering Services
Internal : 7 28 2051
External : 0113 231 2051
Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else. We have checked this email and its attachments for viruses. But you should still check any attachment before opening it. We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes. If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk
Information in this message may be confidential and may be legally privileged. If you have received this message by mistake, please notify the sender immediately, delete it and do not copy it to anyone else.
We have checked this email and its attachments for viruses. But you should still check any attachment before opening it.
We may have to make this message and any reply to it public if asked to under the Freedom of Information Act, Data Protection Act or for litigation. Email messages and attachments sent to or from any Environment Agency address may also be accessed by someone other than the sender or recipient, for business purposes.
If we have sent you information and you wish to use it please read our terms and conditions which you can get by calling us on 08708 506 506. Find out more about the Environment Agency at www.environment-agency.gov.uk