关于informix脚本更改主键问题

underhiswing 2013-01-12 01:41:27
#!/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 文件还是其他类型的文件。如果有知道的请说详细些!感激不尽!

...全文
107 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
underhiswing 2013-01-12
  • 打赏
  • 举报
回复
各位大神,求教

51,409

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧