如何导出一堆的表

qazsew 2003-09-15 12:01:59
我想从一个库中导出好多的表到另一个库中,这些表都不是整张表完全导出的,都是用select选出的。
我写了一个.sql文件,把这些select语句都写进去了,然后用go分开。
请问如果用此文件把这个库里的表导到另外的库里。
需要用什么工具。
...全文
22 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
qazsew 2003-09-17
  • 打赏
  • 举报
回复
DTS只能用如下2种方式导出表:
1、选择几张表,然后将其中的记录全部导出(如果选择其中的几条导就不行了)
2、用一条SQL导出(但不能用多条SQL)

我需要的是:用多条SQL导出多个表中的多个记录到新的库中,并建立相应的表和添加相应的记录。

请问该怎么做
qazsew 2003-09-17
  • 打赏
  • 举报
回复
tjan(安安)
你能说一下具体步骤吗?我试过了,不行,不能用select过滤。

zjcxc(邹建)
你说的是执行一个sql批处理,这个批处理是不能导出数据的,执行一下,让你看看结果还行,但要是导到另一个库中就没招了。
txlicenhe 2003-09-17
  • 打赏
  • 举报
回复
就用Select不也行么?
zjcxc 2003-09-17
  • 打赏
  • 举报
回复
运行对话框中执行:
isql /S"服务器名" /U"用户名" /P"密码" /i"你的sql文件名"


或者在查询分析器,打开你的sql文件,按F5运行.

或者在查询分析器中执行:
exec master..xp_cmdshell 'isql /S"服务器名" /U"用户名" /P"密码" /i"你的sql文件名"'
tjan 2003-09-17
  • 打赏
  • 举报
回复
dts 可以对每个表分别设定检索条件的
friendliu 2003-09-15
  • 打赏
  • 举报
回复
用DTS就行了
pengdali 2003-09-15
  • 打赏
  • 举报
回复
方丈的:
drop proc proc_insert
go
create proc proc_insert (@tablename varchar(256))
as
begin
set nocount on
declare @sqlstr varchar(4000)
declare @sqlstr1 varchar(4000)
declare @sqlstr2 varchar(4000)
select @sqlstr='select ''insert '+@tablename
select @sqlstr1=''
select @sqlstr2=' ('
select @sqlstr1= ' values ( ''+'
select @sqlstr1=@sqlstr1+col+'+'',''+' ,@sqlstr2=@sqlstr2+name +',' from (select case
-- when a.xtype =173 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.length*2+2)+'),'+a.name +')'+' end'
when a.xtype =104 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(1),'+a.name +')'+' end'
when a.xtype =175 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'
when a.xtype =61 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'convert(varchar(23),'+a.name +',121)'+ '+'''''''''+' end'
when a.xtype =106 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.xprec+2)+'),'+a.name +')'+' end'
when a.xtype =62 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(23),'+a.name +',2)'+' end'
when a.xtype =56 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(11),'+a.name +')'+' end'
when a.xtype =60 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(22),'+a.name +')'+' end'
when a.xtype =239 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'
when a.xtype =108 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.xprec+2)+'),'+a.name +')'+' end'
when a.xtype =231 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'
when a.xtype =59 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(23),'+a.name +',2)'+' end'
when a.xtype =58 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'convert(varchar(23),'+a.name +',121)'+ '+'''''''''+' end'
when a.xtype =52 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(12),'+a.name +')'+' end'
when a.xtype =122 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(22),'+a.name +')'+' end'
when a.xtype =48 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(6),'+a.name +')'+' end'
-- when a.xtype =165 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.length*2+2)+'),'+a.name +')'+' end'
when a.xtype =167 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'
else '''NULL'''
end as col,a.colid,a.name
from syscolumns a where a.id = object_id(@tablename) and a.xtype <>189 and a.xtype <>34 and a.xtype <>35 and a.xtype <>36
)t order by colid

select @sqlstr=@sqlstr+left(@sqlstr2,len(@sqlstr2)-1)+') '+left(@sqlstr1,len(@sqlstr1)-3)+')'' from '+@tablename
-- print @sqlstr
exec( @sqlstr)
set nocount off
end
go
伍子V5 2003-09-15
  • 打赏
  • 举报
回复
用数据转换服务(DTS)是很好的办法,不用写很复杂的程序的。

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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