Solved

Drop selected objects (demo tables) from user_tables as sys

Posted on 2011-03-08
7
581 Views
Last Modified: 2013-12-19
Dear experts and dbas,
I discovered that there is a vast number of users in our Oracle instance, that have the oracle demo tables (demo_customers, emp, salgrade etc) installed.

Since it takes a while to delete them all manually for each user, I'd like to know how I can drop these tables and correlated objects such as triggers, indizes and views at once.

Do you have a script to select a number of tables and delete all associated objects for these tables?

Please be so kind and share your knowledge with me!

Many thanks,

Sebastian
0
Comment
Question by:skahlert2010
  • 3
  • 3
7 Comments
 
LVL 4

Expert Comment

by:kevb258
ID: 35068675
DROP USER user CASCADE;

that normally does the job for me
0
 

Author Comment

by:skahlert2010
ID: 35068828
Thanks kevb258!

Well, I don't want to delete the user scheme itself! In fact I just want to delete the demo tables within all user schemes. I need to be able to specify the tables to delete in order to keep the custom user tables!

Any other ideas?

Brgds!

0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 35068895
You can easily write a script to generate the necessary drop commands.  I would caution you before you do this:  Automatically dropping a tables based on name can be a bad thing.  What if I have a table called EMP but it is NOT the table you think it is...

You can generate the list of tables with:

select 'drop table ' || owner || '.' || table_name || ';' from dba_tables where table_name in ('DEMO_CUSTOMERS','EMP');

If all the referenced objects don't use dynamic SQL you can get a list of them from DBA_DEPENDENCIES.

Indexes should go away when you drop the tables.

Just as a double check:  look for invalid objects before and after the drops.  Anything new that is invalid should be manually checked.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:skahlert2010
ID: 35071136
Hello slightwv!

Thanks for your comment! I intend to delete only tables like "DEMO_CUSTOMERS", which I am sure is an Oracle demo table. I have checked on the dba_dependencies and dba_constraints views.

My final question is if correlated constraints, triggers are also deleted when I drop the tables via dba_tables using the CASCADE option! Do you have any experience with this? Or do I need to delete these objects all manually?

Why am I asking these questions? For curiosity! I am just looking for the most efficient way to delete any objects related to demo_tables in all my schemes.

Thanks for your help!

Regards,

Sebastian
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35071347
>>DEMO_CUSTOMERS", which I am sure is an Oracle demo table.

Not one I've ever heard of but Oracle has so many 'products'.  They just don't typically name sample tables 'DEMO'

>>Or do I need to delete these objects all manually?

Looks like triggers are automatically deleted as well even without cascade.

I have to verify this myself so I created a simple test.

You can expand this test to include any object types in question if needed.
drop table tab1 purge;
create table tab1 (col1 char(1));

create or replace trigger tab1_trig
before insert on tab1
for each row
begin
	null;
end;
/

show errors

select object_type from user_objects where object_name='TAB1_TRIG';

drop table tab1;

select object_type from user_objects where object_name='TAB1_TRIG';

Open in new window

0
 

Author Comment

by:skahlert2010
ID: 35079953
Hello slightwv!

I just tested if triggers are deleted simultaneously with the table itself and can confirm it works!
However, the only objects that seem to be persistent are sequences. They are not deleted when the table is dropped and need to be deleted manually. The only difficulty is to find out,w hich respective sequence belongs to which table if names seq_names. If you have an idea, please don't hesitate to tell me!

I will close the question know and award you the points for your good help!

Thank you!
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35084375
The problem is sequences are not tied to tables at the database layer.  They are set up and used at the application layer.  They are independent objects.

If your shop set them up one-to-one then hopefully the sequence names are tied to table names in some way.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Via a live example, show how to take different types of Oracle backups using RMAN.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question