有没有这样的工具?

joejoe1991 2010-12-05 11:51:30
命令行下的工具。
可以将整个数据库导出成为SQL文件。
有没有这样的工具啊?
就像mysqldump那样的。
...全文
112 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
joejoe1991 2010-12-10
  • 打赏
  • 举报
回复
我是要cmd下的工具。。
老张一笑 2010-12-10
  • 打赏
  • 举报
回复
cmd下可以运行sql脚本,就是说可以省略查询分析器工具
cjh200102 2010-12-10
  • 打赏
  • 举报
回复
SQL自己有这功能
kongdie 2010-12-06
  • 打赏
  • 举报
回复
sql server不是自带了生成sql脚本的工具吗
changeZ 2010-12-06
  • 打赏
  • 举报
回复
Mark.

学习了.
dawugui 2010-12-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 joejoe1991 的回复:]
假如一个表里面有两千万行记录,用这个存储过程生成INSERT的话大概需要多少时间啊?
[/Quote]不知道,你自己试试吧.
joejoe1991 2010-12-05
  • 打赏
  • 举报
回复
假如一个表里面有两千万行记录,用这个存储过程生成INSERT的话大概需要多少时间啊?
dawugui 2010-12-05
  • 打赏
  • 举报
回复
[Quote=引用楼主 joejoe1991 的回复:]
命令行下的工具。
可以将整个数据库导出成为SQL文件。
有没有这样的工具啊?
就像mysqldump那样的。
[/Quote]

1.如果是表结构,存储过程等东西,可以在企业管理器中去用导出脚本这个功能.
也可以参考如下的一段代码去直接生成表结构.
SELECT TableName=o.name,OWNER=USER_NAME(o.uid),TableDescription=ISNULL(ptb.value,N''),
FieldId=c.colid,FieldName=c.name,
FieldType=QUOTENAME(t.name)
+CASE
WHEN t.name IN (N'decimal',N'numeric')
THEN N'('+CAST(c.prec as varchar)+N','+CAST(c.scale as varchar)+N')'
WHEN t.name=N'float'
OR t.name like N'%char'
OR t.name like N'%binary'
THEN N'('+CAST(c.prec as varchar)+N')'
ELSE N'' END
+CASE WHEN c.isnullable=1 THEN N'' ELSE N' NOT' END+N' NULL',
FieldDescription=ISNULL(pfd.value,''),
DefileLength=c.length,
FieldDefault=ISNULL(df.text,N''),
IsIDENTITY=COLUMNPROPERTY(o.id,c.name,N'IsIdentity'),
IsComputed=COLUMNPROPERTY(o.id,c.name,N'IsComputed'),
IsROWGUID=COLUMNPROPERTY(o.id,c.name,N'IsRowGuidCol'),
IsPrimaryKey=CASE WHEN opk.xtype IS NULL THEN 0 ELSE 1 END
FROM sysobjects o
JOIN syscolumns c
ON c.id=o.id
AND OBJECTPROPERTY(o.id,N'IsUserTable')=1
JOIN systypes t
ON t.xusertype=c.xusertype
LEFT JOIN syscomments df
ON df.id=c.cdefault
LEFT JOIN sysproperties ptb
ON ptb.id=o.id and ptb.smallid=0
LEFT JOIN sysproperties pfd
ON pfd.id=o.id and pfd.smallid=c.colid
LEFT JOIN sysindexkeys idxk
ON idxk.id=o.id
AND idxk.colid=c.colid
LEFT JOIN sysindexes idx
ON idx.indid=idxk.indid
AND idx.id=idxk.id
AND idx.indid NOT IN(0,255)
LEFT JOIN sysobjects opk
ON opk.parent_obj=o.id
AND opk.name=idx.name
AND OBJECTPROPERTY(opk.id,N'IsPrimaryKey')=1
ORDER BY o.name,c.colid


2.如果是要表的数据也生成insert之类的语句,参考如下的存储过程.
将表数据写成Insert Into语句的存储过程

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE proc pGetInsertSQL (@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
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

lg314 2010-12-05
  • 打赏
  • 举报
回复
可以的,默认的生成脚本的工具就可以了.只要把导出数据那一项设置为true
水妹妹 2010-12-05
  • 打赏
  • 举报
回复
只能生产脚本,数据要导入导出
billpu 2010-12-05
  • 打赏
  • 举报
回复
黑客工具 嘿嘿
njlywy 2010-12-05
  • 打赏
  • 举报
回复
claro 2010-12-05
  • 打赏
  • 举报
回复
;).
reggiekiller 2010-12-05
  • 打赏
  • 举报
回复
sql server是不是自带了生成sql脚本的工具

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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