如何用SQL语句从TXT文件中导入数据?

panhao 2001-09-30 08:16:20
如何用SQL语句从TXT文件中导入数据?
SQL SERVER 7.0
...全文
271 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tiantianpb 2002-07-10
  • 打赏
  • 举报
回复
CREATE PROCEDURE dt_databaserestore @str_restorepath varchar(255),@str_databasename varchar(50),@str_tablename varchar(50) AS
declare @str_sqlexecute varchar(255)
if @str_tablename='' or @str_tablename=null
begin
declare restoretable_cursor cursor for
select sysobjects.name from sysobjects where sysobjects.type='U'
open restoretable_cursor
fetch next from restoretable_cursor into @str_tablename
while @@fetch_status=0
begin
select @str_sqlexecute='truncate table '+@str_tablename
execute(@str_sqlexecute)
select @str_sqlexecute='bcp '+@str_databasename+'..'+@str_tablename+' in '+ @str_restorepath+'\'+@str_tablename+'.bac -c -U sa -P'
exec master..xp_cmdshell @str_sqlexecute
fetch next from restoretable_cursor into @str_tablename
end
deallocate restoretable_cursor
end
else
begin
select @str_sqlexecute='truncate table '+@str_tablename
execute(@str_sqlexecute)
select @str_sqlexecute='bcp '+@str_databasename+'..'+@str_tablename+' in '+ @str_restorepath+'\'+@str_tablename+'.bac -c -U sa -P'
exec master..xp_cmdshell @str_sqlexecute
end
看看以上的存储过程
kfh666 2002-07-10
  • 打赏
  • 举报
回复
up
huobao 2002-07-10
  • 打赏
  • 举报
回复
up
eastseaofdragon 2001-09-30
  • 打赏
  • 举报
回复
gz
zhuzhichao 2001-09-30
  • 打赏
  • 举报
回复
1.用dos命令行工具bcp.exe:
如:
bcp master.dbo.sysobjects in c:\aa.txt /Usa /P /S10.60.80.21 /C -h -k -E -f -c

2.用MS的xpsql70.dll封裝的擴展存儲過程xp_cmdshell:
如:
xp_cmdshell 'd:\mssql7\binn\bcp.exe master.dbo.sysobjects in c:\aa.txt /Usa /P /S10.60.80.21 /C -h -k -E -f -c'
xngu 2001-09-30
  • 打赏
  • 举报
回复
SQL语句好像是无法操作除数据库以外的文件,你用数据窗口函数不行吗?

1,079

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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