patternMinor
Delete all the data from all tables
Viewed 0 times
tablesthedeleteallfromdata
Problem
I have a little problem. I have to delete all the data from our database. I don't want to drop tables, only delete the data sets.
These are 47 tables in total.
I tried the following:
But that is not valid. How can I efficiently remove all the data from all my tables?
These are 47 tables in total.
I tried the following:
Delete FROM(select TABLE_NAME from USER_TABLES);
Delete FROM(select * from ALL_ALL_TABLES Where OWNER = 'DB_NAME')But that is not valid. How can I efficiently remove all the data from all my tables?
Solution
Generate the statements you need
Even better would be using
select 'DELETE FROM '||table_name||' ;' from user_tables;Even better would be using
TRUNCATE instead of DELETE. That would prevent generating extra redo vectors in the redo log - in the end all you want to do is just get rid of the data. It would also avoid all actions by any DELETE triggers that the tables have.select 'TRUNCATE TABLE '||table_name||' ;' from user_tables;Code Snippets
select 'DELETE FROM '||table_name||' ;' from user_tables;select 'TRUNCATE TABLE '||table_name||' ;' from user_tables;Context
StackExchange Database Administrators Q#74519, answer score: 7
Revisions (0)
No revisions yet.