Chinaunix首页 | 论坛 | 博客
  • 博客访问: 39813
  • 博文数量: 19
  • 博客积分: 850
  • 博客等级: 准尉
  • 技术积分: 220
  • 用 户 组: 普通用户
  • 注册时间: 2005-11-18 00:03
文章分类

全部博文(19)

文章存档

2010年(1)

2009年(17)

2008年(1)

我的朋友
最近访客

分类:

2009-09-03 12:05:21

在数据库没有做update statistics前,systables表里各表记录数与实际表记录数差别比较大,这种情况下可以通过以下方法统计各表的记录数.
countrecord.sh dbsname
-------------------------------------
#!/bin/ksh
if [ $# -ne 1 ];then
cat << EOF
Usage: $0 dbsname
       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

阅读(803) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~