关于informix脚本更改主键问题
#!/bin/sh
#################################################
#功能: informix 修改数据库主键
#################################################
chg_primary_key()
{
if [ $# -ne 2 ];then
echo "<ERROR> Uargs: chg_primary_key tableName primaryKey /n[$*]"
exit 1
fi
_tableName="$1"
_primaryKey="$2"
alias dbaccess='dbaccess'
#查出老的主键约束名
_constrName=`dbaccess remotedb 2>> tmp.txt << EOF | xargs | cut -d ' ' -f2
select constrname from sysconstraints where constrtype='P'
and tabid= ( select tabid from systables where tabname = '$_tableName' ) ;
EOF `
if [ -z "$_constrName" ] || [ "$_constrName" = "constrname" ];then
echo "<ERROR>主键名查出为空!"
exit 1
fi
#修改主键
dbaccess remotedb << EOF
alter table $_tableName drop constraint $_constrName;
alter table $_tableName add constraint
primary key ($_primaryKey) constraint $_constrName;
EOF
}
#debitrec修改主键为(policyno,classcode,loandate)
chg_primary_key debitrec policyno,classcode,loandate
---------------------------------------------------------------------------------------
以上的脚本能用么?使用什么命令执行?能用的话是 *.sh 文件还是其他类型的文件。如果有知道的请说详细些!感激不尽!