Peter,
Dagon's script is excellent. But for proper performance, you should have Oracle regularly gather statistics about your tables and indexes. There are a variety of commands that you can issue that gather statistics either for the entire database, for individual schemae, or for individual tables and indexes.
One of the statistics that results from gathering statistics is NUM_ROWs:
Code:
select num_rows,table_name
from user_tables where table_name like 'S%'
and num_rows is not null;
NUM_ROWS TABLE_NAME
-------- --------------
2345 SALES
6 SAMBO
6 SASA
8 SAY
6 SESS
1 SID
0 SRM_PROJECTS
4 STEVE_SOURCE
4 STEVE_TARGET
5 STOCKS
3 SYS_A_INVOICES
2 SYS_B_INVOICES
25 S_EMP
If there is no datum in NUM_ROWS for a particular table, then that means that no one has gathered statistics for that table...not a good thing from a optimiser-performance perspective. So, where statistics are null for a particular table, that is the first clue that you should gather statistics.
If you need to audit regularly the number of rows in tables, then you do not need to waste lots of processing cycles by doing full-table scans for each iteration of the query since the data already resides in NUM_ROWS of *_TABLES (i.e., USER_..., ALL_..., and DBA_...) if you are (re-)gathering statistics as often as you should.
Let us know if you have questions.
![[santa] [santa] [santa]](/data/assets/smilies/santa.gif)
Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services:
www.dasages.com]