在数据库没有做update statistics前,systables表里各表记录数与实际表记录数差别比较大,这种情况下可以通过以下方法统计各表的记录数.
脚本如下:

  1. #!/bin/ksh  
  2. if [ $# -ne 1 ];then  
  3.     cat << EOF 
  4.         Usage: $0 dbsname  
  5. EOF  
  6.     exit 1  
  7. fi  
  8.  
  9. dbsname="$1" #数据库名  
  10.  
  11. echo "unload to tables.txt  
  12. select tabname from systables where tabname not like 'sys%' and tabname not like ' %' and tabtype='T';">tables.sql  
  13. dbaccess $dbsname tables.sql 2>/dev/null  
  14. cat tables.txt|awk -F"|" '{print $1}'>tables2.txt  
  15. for i in `cat tables2.txt`  
  16.     do  
  17.         #统计数据库表记录数  
  18.         echo "unload to count.txt select \"$i\"||\"\",count(*) from $i;">file.sql  
  19.         dbaccess $dbsname file.sql  
  20.         cat count.txt>>total.txt  
  21.         rm count.txt  
  22.         rm -rf file.sql  
  23. done  
  24. rm -f tables2.txt tables.sql 

本日志由 flyinweb 于 2009-10-28 10:25:21 发表到 数据库技术 中,目前已经被浏览 3817 次,评论 0 次;

作者添加了以下标签: 统计Informix表记录数