如何在bcp导入数据之前自动清空目的表中的数据?

amio 2003-07-15 12:51:11
如题。
我要编写一个自动shell脚本,执行bcp导入数据之前自动将表中的数据删除。
...全文
140 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dennis2001 2003-07-16
  • 打赏
  • 举报
回复
同意ehxz的办法。
amio 2003-07-16
  • 打赏
  • 举报
回复
解决了,我编写了一个shell脚本,内容如下:
#!/bin/sh
#The first arg is the username to operate the database.
#The second arg is the password of the username.
#The third arg is the database name;
#The forth arg is the bcp direction(in or out).

if [ $# -ne 4 ]
then
printf "Usage: bcpsh username password dbname direction([in/out]))\n\n"
exit 1
else
un=$1
pwd=$2
dbname=$3
dt=$4
fi
if [ $dt = "in" ]
then
f=deleteScript.sql
printf "------------------------------------------------"
printf "\nDeleting the old data ...\n" "$f"
while read tname
do
printf "DELETE FROM $tname \ngo\n" >> $f
done < tList.cfg

isql -U$un -P$pwd -D$dbname < $f
rm $f
fi

while read tname
do
printf "\n\n------------------------------------------------"
printf "\nbcp %s %s ...\n" "$dt" "$tname"
bcp $dbname..$tname $dt ./dataFiles/$tname -U$un -P$pwd -c
done < tList.cfg
sybasebbs 2003-07-15
  • 打赏
  • 举报
回复
前面加个SQL吧,truncate table ****
好象没有什么别的办法吧

2,598

社区成员

发帖
与我相关
我的任务
社区描述
Sybase相关技术讨论区
社区管理员
  • Sybase社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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