同城约会| 杂志期刊| 小说| 两性论坛| 军事电影| 两性知识| 电脑知识| 汽车| 旅游| 收藏

使用 Informix 系统目录(1)

来源: 作者: 出处:综艺读书 2005-11-29 
关 键 词:邮件  数据库  数据仓库  设计  解决方案  
上一页 1 2 3 

清单 2. 功能相当的 awk 脚本


#!/bin/ksh
###########################################################
#
# findcol database column
#
# returns any table or column within 'database' that has some
# portion of 'column' within it's name
#
# Jack Parker 2002
#
###########################################################
echo "
select tabname[1,25], colname[1,25], coltype, collength
  from systables a, syscolumns b
 where a.tabid = b.tabid
   and (colname matches \\"*$2*\\" or tabname matches \\"*$2*\\");
" | dbaccess $1 - 2>/dev/null | tail +4l | grep -v ^$ | awk '
BEGIN {
dtp[0]="char"
dtp[1]="smallint"
dtp[2]="integer"
dtp[3]="float"
dtp[4]="smallfloat"
dtp[5]="decimal"
dtp[6]="serial"
dtp[7]="date"
dtp[8]="money"
dtp[9]="unknown"
dtp[10]="datetime"
dtp[11]="byte"
dtp[12]="text"
dtp[13]="varchar"
dtp[14]="interval"
dtp[15]="nchar"
dtp[16]="nvarchar"
dtp[17]="unk"
dtp[18]="unk"
dtp[19]="unk"
dtp[20]="unk"

datp[1] = "year"
int_start[1]=1
int_end[1]=5
datp[3] = "month"
int_start[3]=5
int_end[3]=7
datp[5] = "day"
int_start[5]=7
int_end[5]=9
datp[7] = "hour"
int_start[7]=9
int_end[7]=11
datp[9] = "minute"
int_start[9]=11
int_end[9]=13
datp[11] = "second"
int_start[11]=13
int_end[11]=15
datp[12] = "fraction(1)"
int_start[12]=15
int_end[12]=16
datp[13] = "fraction(2)"
int_start[13]=16
int_end[13]=17
datp[14] = "fraction(3)"
int_start[14]=17
int_end[14]=18
datp[15] = "fraction(4)"
int_start[15]=18
int_end[15]=19
datp[16] = "fraction(5)"
int_start[16]=19
int_end[16]=20
}
function fixnm(coll,tp)
{
   i = int(coll / 256)
   j = coll % 256
   if (tp == 0) {
if (j > i ) strg=i
else strg = sprintf("%s,%s",i,j)
}
   else {
if (i == 0) strg=j
else strg = sprintf("%s,%s",j,i)
}
   return strg
}
function fixdt(coll)
{
   i = coll % 16 + 1
   j = int((coll % 256) / 16 ) + 1
   k = int(coll / 256)
   ln = int_end[i] - int_start[j]
   ln = k - ln
   if (ln == 0 || j > 11) { strg = sprintf("%s to %s", datp[j], datp[i]) }
   else {
k int_end[j] - int_start[j]
k = k + ln
strg = sprintf("%s (%d) to %s", datp[j], k, datp[i])
}
   return strg
}
{
# Tab, colname, type, length
outstrg=""
tabname=$1
colname=$2
nonull=$3/256
coltype=$3%256
collength=$4
outstrg=dtp[coltype]
if (coltype == 0) {outstrg=sprintf("%s(%s)",outstrg, collength)}
if (coltype == 5 || coltype == 8 ) {
outstrg=sprintf("%s(%s)",outstrg,fixnm(collength,0)) }
if (coltype == 13 ) {outstrg=sprintf("%s(%s)",outstrg,fixnm(collength,1)) }
if (coltype == 10 || coltype == 14 ) {
outstrg=sprintf("%s(%s)",outstrg,fixdt(collength)) }
printf("%-20s %-20s %-25s\\n", tabname, colname, outstrg)
}' 

清单 3. depend.sh


#!/bin/ksh
###############################################################
#
# Quick script thrown together to find dependencies on 
# a table.
#
# Usage:
#  depend.sh database table
#
# This will list all tables which refer to this table either 
# by view or by foreign key.  It will also list any tables 
# that this table depends on.  It will recurse through a 
# dependency chain.
#
# Jack Parker 2003
#
###############################################################

find_par_view()
{
dbaccess $1 - 2>/dev/null <<EOF
output to pipe "cat" without headings
select trim(b.tabname)
from sysdepend c, systables a, systables b
where btabid=a.tabid
  and dtabid=b.tabid
  and b.tabname = "$2";
EOF
}

find_child_view()
{
dbaccess $1 - 2>/dev/null <<EOF
output to pipe "cat" without headings
select trim(b.tabname)
from sysdepend c, systables a, systables b
where btabid=a.tabid
  and dtabid=b.tabid
  and a.tabname = "$2";
EOF
}

find_par_fk()
{
dbaccess $1 - 2>/dev/null <<EOF
output to pipe "cat" without headings
select trim(d.tabname) || ' ' || trim(constrname) || ' ' || state
from systables a, sysconstraints b, sysreferences c, systables d, 
  sysobjstate e
where constrtype='R'
  and a.tabid=b.tabid
  and b.constrid=c.constrid
  and b.constrname=e.name
  and c.ptabid=d.tabid
  and a.tabname = "$2";
EOF
}

find_child_fk()
{
dbaccess $1 - 2>/dev/null <<EOF
output to pipe "cat" without headings
select trim(d.tabname) || ' ' || trim(constrname) || ' ' || state
from systables a, sysconstraints b, sysreferences c, systables d, 
sysobjstate e
where constrtype='R'
  and a.tabid=b.tabid
  and b.constrid=c.constrid
  and b.constrname=e.name
  and c.ptabid=d.tabid
  and d.tabname = "$2";
EOF
}

rec_pfk()
{
idnt="$idnt-"
find_par_fk $1 $2 | grep -v "^$" |
while read junk
do
        echo $idnt "Parent of FK: $junk"
        tab=`echo $junk | cut -d" " -f1 `
        rec_pfk $1 $tab
done
idnt=`echo $idnt | awk '{a=length($0)-1; print substr($0,1,a)}'`
}

rec_cfk()
{
idnt="$idnt-"
find_child_fk $1 $2 | grep -v "^$" |
while read junk
do
        echo $idnt "Child of FK: $junk"
        tab=`echo $junk | cut -d" " -f1 `
        rec_cfk $1 $tab
done
idnt=`echo $idnt | awk '{a=length($0)-1; print substr($0,1,a)}'`
}

rec_pvw()
{
idnt="$idnt-"
find_par_view $1 $2 | grep -v "^$" |
while read tab
do
        echo $idnt "Parent View : $tab"
        rec_cfk $1 $tab
done
idnt=`echo $idnt | awk '{a=length($0)-1; print substr($0,1,a)}'`
}

rec_cvw()
{
idnt="$idnt-"
find_child_view $1 $2 | grep -v "^$" |
while read tab
do
        echo $idnt "Child of View : $tab"
        rec_cfk $1 $tab
done
idnt=`echo $idnt | awk '{a=length($0)-1; print substr($0,1,a)}'`
}

echo "

Database: $1
"
idnt=""
echo "Searching for tables that ($2) has an FK to:"
rec_pfk $1 $2
idnt=""
echo "Searching for tables that refer to ($2) with an FK:"
rec_cfk $1 $2
idnt=""
echo "Searching for Parent tables for potential view ($2):"
rec_pvw $1 $2
idnt=""
echo "Searching for Child tables for table ($2):"
rec_cvw $1 $2

免责声明

本文包含样本代码。IBM 授予您(“被许可方”)使用这个样本代码的非专有的、版权免费的许可证。然而,该样本代码是以“按现状”的基础提供的,没有任何形式的(不论是明示的,还是默示的)保证,包括对适销性、适用于特定用途或非侵权性的默示保证。IBM 及其许可方不对被许可方由于使用该软件所导致的任何损失负责。任何情况下,无论损失是如何发生的,也不管责任条款怎样,IBM 或其许可方都不对由使用该软件或不能使用该软件所引起的收入的减少、利润的损失或数据的丢失,或者直接的、间接的、特殊的、由此产生的、附带的损失或惩罚性的损失赔偿负责,即使 IBM 已经被明确告知此类损害的可能性,也是如此。

关于作者

Jack Parker是一名系统架构设计师,在过去的十五年里,他一直从事构建和管理基于 Informix 的解决方案。过去的六年时间里,他一直从事数据仓库行业的工作。他偶尔也为 comp.databases.informix 撰写文章、发表演讲和投稿。他是位于新罕布什尔州南部的咨询公司 Arten Technology Group 的合伙人。他的电子邮件地址是 jparker@artentech.com。



更多文章 更多内容请看informix  系统安全设置  系统安装手册专题,或进入讨论组讨论。
上一页 1 2 3 
收藏此文】【 】【打印】【关闭
较早的文章:
较新的文章:IBM Informix Dynamic数据库服务器介绍
相关图文阅读
频道图文推荐
综艺读书宗旨
相关专题
·系统优化大全 (13888篇文章)
·系统安全设置 (18678篇文章)
·系统安装手册 (16366篇文章)
·系统备份专题 (13499篇文章)
·informix (193篇文章)
·系统维护手册 (13037篇文章)
热点标签: 邮件  数据库  数据仓库  设计  解决方案  
最新技术文档
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
百度推荐,商机无限
搜索您感兴趣的内容
Web 全站
综艺电脑频道编辑信箱  告诉我们您想看的专题或文章

Google

友情互链 | 收藏本站 | 联系我们 | 在线留言 | 京ICP备08008424号|