如何导出一堆的表

qazsew 2003-09-15 12:01:59
我想从一个库中导出好多的表到另一个库中,这些表都不是整张表完全导出的,都是用select选出的。
我写了一个.sql文件,把这些select语句都写进去了,然后用go分开。
请问如果用此文件把这个库里的表导到另外的库里。
需要用什么工具。
...全文
21 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)是很好的办法,不用写很复杂的程序的。
下载了一大堆的免费文档 我也贡献一个我自己写的PowerDesigner16 5的使用文档 这个是公司领导让我自己写来做使用指导用的 写的仓促 多有不恰当的地方 望大家见谅 1 这个是16 5的版本 2 这个是以oralce11g为模板 3 文档目录如下: PowerDesigner 16 5 指导 1 一 安装 3 二 新建模板步骤 这里以Oracle11g数据库为例 3 1 新建Model 3 2 Modle设置 3 3 模板设置 4 4 右侧工具条 5 5 新建测试包 6 6 配置 6 6 1进入模板 6 6 2新建 6 6 3修改 7 6 4添加注释 7 6 5属性设置 8 6 5 1 8 6 5 2 9 6 5 3 9 6 5 4 9 6 6添加关系 10 6 7关系设置 10 6 8模板保存 12 6 9查看模板 12 三 模板导入脚本 12 1 打开Change Current DRMS 12 2 删除多余双引号 13 3 生成脚本 13 四 配置数据库 15 1 点击Database >Configure Connections 15 2 选择第三个系统数据根源 17 3 选择Oracle in OraDb11g hom1 选择下一步 然后点击完成 17 4 数据源配置 18 5 配置成功 19 五 反向工程生成模板 20 1 按照二 1和二 2生成一个空模板 20 2 选择Database >Update Model from Database 20 3 选择数据源 20 4 数据源配置 21 5 选择反向工程导出对象 22 6 可以看到反向工程自动生成的模板 即代操作工程 23 六 生成HTML文档 24 1 点击Report >Generate Report 24 2 配置完成 点击确认即可 24 3 打开html文档 应该是下图格式 25">下载了一大堆的免费文档 我也贡献一个我自己写的PowerDesigner16 5的使用文档 这个是公司领导让我自己写来做使用指导用的 写的仓促 多有不恰当的地方 望大家见谅 1 这个是16 5的版本 2 这个是以oralce11g为模板 3 文档 [更多]

27,579

社区成员

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

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