Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2008
    Location
    Toronto, Canada
    Posts
    2,367

    Unanswered: count tables in all databases

    I need to count the number of tables in all databases. Here is what I have:

    Code:
    typeset -i cnt=0
    typeset -i cnt_t
    
    for i in `db2 list db directory | grep -p -i indirect | grep "Database name" | awk {' print $4 '}`
    do
    echo $i
    db2 connect to $i > /dev/null
    cnt=$(db2 -x "select count(*) from syscat.tables where type = 'T'")
    echo $cnt
    cnt_t=cnt_t+cnt
    #cnt_t+=cnt
    done
    echo "All DB"
    echo $cnt_t
    Is there a better way to write the following two lines?
    cnt=$(db2 -x "select count(*) from syscat.tables where type = 'T'")
    cnt_t=cnt_t+cnt

  2. #2
    Join Date
    Nov 2011
    Posts
    334
    hi,
    What do you mean "the better way"?
    What is the problem with this?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •