标签归档:COUNT

统计各表记录数SHELL(for informix)

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

#!/bin/ksh  
if [ $# -ne 1 ];then  
    cat << EOF 
        Usage: $0 dbsname  
EOF  
    exit 1  
fi  
 
dbsname="$1" #数据库名  
 
echo "unload to tables.txt  
select tabname from systables where tabname not like 'sys%' and tabname not like ' %' and tabtype='T';">tables.sql  
dbaccess $dbsname tables.sql 2>/dev/null  
cat tables.txt|awk -F"|" '{print $1}'>tables2.txt  
for i in `cat tables2.txt`  
    do  
        #统计数据库表记录数  
        echo "unload to count.txt select \"$i\"||\"\",count(*) from $i;">file.sql  
        dbaccess $dbsname file.sql  
        cat count.txt>>total.txt  
        rm count.txt  
        rm -rf file.sql  
done  
rm -f tables2.txt tables.sql