Chinaunix首页 | 论坛 | 博客
  • 博客访问: 41902
  • 博文数量: 7
  • 博客积分: 257
  • 博客等级: 二等列兵
  • 技术积分: 118
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-09 22:13
文章分类
文章存档

2012年(5)

2011年(2)

我的朋友

分类: LINUX

2012-03-18 12:48:59

统计informix数据库某用户表记录数
用法:
table_count_inf.sh dbname username

table_count_inf.sh内容如下:

if [ "$#" -ne "2" ]
then
    echo "useage: $0 dbname user"
    exit
fi
dbsname="$1"
owner="$2"

#取表名
echo "unload to tmp.txt
select tabname from systables where owner='$owner' order by 1;" >  table.sql
dbaccess $dbsname table.sql
awk -F"|" '{print $1}' tmp.txt >tables.txt
rm tmp.txt

#生成统计各表记录数的sql语句
echo "unload to count_inf.txt" > tmp.sql
for i in `cat tables.txt`
do
    echo "select '$i',trunc(count(*),0)||\"\" from $i 
    union all">>tmp.sql
done
sed '$d' tmp.sql >  file.sql
echo ";" >>file.sql
rm tmp.sql

#统计各表行数,结果到count_inf.txt
dbaccess $dbsname file.sql
rm table.sql file.sql tables.txt

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