把SQL SERVER里表里的数据导出成为insert into 脚本
来源:互联网 发布:内蒙古软件企业评估 编辑:程序博客网 时间:2024/05/08 07:39
--于数据库里创建如下存储过程
--使用方式 :proc_insert ' 要导出的表名'
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
- 把SQL SERVER里表里的数据导出成为insert into 脚本
- 把SQL SERVER里表里的数据导出成为insert into 脚本
- 把SQL SERVER里表里的数据导出成为insert into 脚本
- 把SQL SERVER里表里的数据导出成为insert into 脚本
- 如何把SQL SERVER里表里的数据导出成为insert into 脚本
- 把SQL SERVER里表里的数据导出成为insert into 脚本,终于找到这个过程了
- SQL SERVER:把表里的数据导出成为INSERT INTO脚本的存储过程
- SQL SERVER:把表里的数据导出成为INSERT INTO脚本的存储过程
- 将Oracle表里的数据导出生成insert into 脚本
- SQL Server 2005 导出包含(insert into)数据的SQL脚本 (使用存储过程)
- SQL Server 2005 导出包含(insert into)数据的SQL脚本 (使用存储过程)
- 把表里的数据导出生成脚本
- sql server 数据库导出表里所有数据成insert 语句
- sql server 数据库导出表里所有数据成insert 语句
- 实现将SQLServer表里的数据导出为insert脚本
- sql2005数据导出sql脚本为insert into
- sql2005数据导出sql脚本为insert into
- 用PL/SQL Developer 把oracle表里的数据导成insert语句(不积跬步,无以至千里)
- 从IT精英到IT民工 互联网已沦为高危行业
- 一个获取相对路径的方法(C#)
- Debian中文输入法fcitx总结
- 什么是中间件?
- Mac OS X Programming读书笔记1 - 系统架构
- 把SQL SERVER里表里的数据导出成为insert into 脚本
- 遥感图像分类综述
- 脱离IDE的一个简单C#程序(下)
- 要让软件项目失败很容易
- linux操作系统下c语言编程入门
- 工作前的感想
- 关于方法CEikonEnv::Static()方法和宏iEikonEnv的使用区别
- 27歲以上單身男人100條忠告![转帖]
- 细说框架风云 JSF能否拯救WEB江湖