If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > How to delete all rowa in all tables of a schema in Oracle?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-11-04, 04:19
Ach Ach is offline
Registered User
 
Join Date: Mar 2004
Posts: 370
How to delete all rowa in all tables of a schema in Oracle?

Hi all,

I want to delete all records of all tables of a schema and think there should be some statement for this but I dont know how?

may you help?
Reply With Quote
  #2 (permalink)  
Old 08-11-04, 08:41
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
As this question is Oracle specific, I'd suggest that you post it in the Oracle forum. One of the Oracle folks can probably answer your question definitively without even needing to look it up!

-PatP
Reply With Quote
  #3 (permalink)  
Old 08-11-04, 09:58
spvijay spvijay is offline
Registered User
 
Join Date: Feb 2004
Location: Eternity
Posts: 31
No simple statement available

There is no simple statement available to delete only the tables.
U can instead use
DROP USER <username> CASCADE.
But caution.....this will delete everything belonging to the user tables, views, sequences..etc.
If u want to delete only the table of a schema
then u can write a PL/SQL which will query for all the table from user_objects and then execute statements to delete the data from the tables
__________________
Obviousness is the enemy of Correctness
--Bertand Russel
Reply With Quote
  #4 (permalink)  
Old 08-12-04, 03:26
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
PL/SQL procedure would do the work indeed.

Perhaps another suggestion - write a query and spool its output to an .sql file and then run it. Such as:
Code:
> set heading off;
> set feedback off;
> 
> spool truncall.sql
> 
> select 'truncate table ' || tname ||';' from tab where tabtype = 'TABLE';
> 
> spool off;
> 
> @truncall
Why 'truncate' and not 'delete'? Delete saves all the deleted records in rollback segment(s) which slows things down.

However, you might need to run this script several times due to referential integrity constraints which might prevent some tables to be truncated (you can't delete parent while child exists).
Reply With Quote
  #5 (permalink)  
Old 08-12-04, 20:53
Ach Ach is offline
Registered User
 
Join Date: Mar 2004
Posts: 370
Red face Thanx but my q was another thing!

Thanx all for help,
but I want to delete all the records from all my tables not truncating all tables.Any idea?
Reply With Quote
  #6 (permalink)  
Old 08-12-04, 21:35
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
What difference do you see between deleting all of the rows and truncating the table?

-PatP
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On