Tuesday 7 August 2012

give me table names and row counts (for a schema) in a table oracle syntax

I do this all of the time.  When I’m converting data, doing upgrades or just for fun!  I need to list all of the tables in an owner that have data.  I know there are 10000 ways of doing this, but this is what generally works when I use oracle or SQLServer or AS/400.  With a slight tweak of syntax!

create table ol900.dataaudit (tablename varchar(20) not null, rowcount integer) ;

run the results of the following:  This is going to get row counts for ALL tables in CRP

select 'insert into ol900.dataaudit (select ' || '''' || table_name || '''' || ', count(1) from crpdta.' || table_name || ');' from all_tables where owner = 'CRPDTA';

Look at your results.

select * from ol900.dataaudit order by rowcount desc ;

No comments: