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 > Database Server Software > DB2 > Table Count

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-30-04, 16:29
sks sks is offline
Registered User
 
Join Date: Sep 2003
Posts: 19
Table Count

I am running DB2 UDB 7.2 trying to get count of rows in the entire schema! Is there any single command vs typing in 566 individual sql command to get the counts?

Please advice!
Reply With Quote
  #2 (permalink)  
Old 01-30-04, 16:47
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Re: Table Count

I don't know of any SQL which can do this ..

I can think of two options :

1) Do RUNSTATS on the tables and then select tabname,card from syscat.tables

2) Do a Unix Script

db2 "select tabname from syscat.tables where tabschema='SCHEMA1'" | while read tname
do
db2 "select '$tabname',count(*) from $tabname"
done

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 01-30-04, 16:50
sks sks is offline
Registered User
 
Join Date: Sep 2003
Posts: 19
Thx! That worked perfect!
Reply With Quote
  #4 (permalink)  
Old 01-30-04, 17:10
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Some other possiblities:

If you don't have up to date statistics from a runstats on all tables, the run the following command:

db2 reorgchk update statistics on table all

To double check that that stats are collected for all tables, run the following:

select tabschema, tabname, type from syscat.tables
where card = -1 and type = 'T'


Then run this query (make sure tabschema value is all caps).

select count(*), sum(card) from syscat.tables
where tabschema = '?????????' and card <> -1 and type = 'T'

The count(*) will verify the number of tables.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
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