针对任意表导出数据为insert语句(收藏整理)
来源:互联网 发布:淘宝网蒙古族雪纺服装 编辑:程序博客网 时间:2024/05/22 16:18
--首先,在对应的数据库中创建下面存储过程,
--然后,执行proc_insert '表名'导出sql插入语句
--最后,导出sql表中数据的insert sql语句
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
- 针对任意表导出数据为insert语句(收藏整理)
- SQLServer中数据导出为insert语句
- Mongo-JS-导出数据为insert语句
- 把某个表的数据导出成insert语句(数据导出 insert语句)
- SQL 表数据导出insert 语句
- MS SQLServer 将Table中的数据导出为insert语句
- sqlserver 导出数据信息为insert into 语句
- sqlserver 中 将数据 导出为 insert语句 的Proc
- 导出数据库任意表数据为EXCEL
- [转]sql server将表中的数据导出为 insert的sql语句
- 将SQLServer中指定表的数据导出为Insert语句形式
- Oracle数据导出为Insert
- 将Sqlserver表数据导出成insert into语句
- 将Sqlserver表数据导出成insert into语句 .
- 根据MySQL表数据导出INSERT INTO语句的方法
- 如何导出数据(insert into这样的语句)
- workbench只导出数据(含insert语句)
- SQL Server 2005导出表中数据的SQL脚本形式(即INSERT语句)
- 免费看书的电子图书馆(可下载)。。。
- 获取当前Url地址以及参数的函数
- 清除windows密码..
- SQL注入攻击
- 一个女孩写给女孩的话-不管是男是女看看吧,看看我们做了里面的多少
- 针对任意表导出数据为insert语句(收藏整理)
- 用VB写监控程序
- How to Drag and Drop in JavaScript(怎样通过JavaScript拽动窗口)
- visual c++ 的插件
- c# 实现MD5,SHA1,SHA256,SHA512等常用加密算法
- 关于记录的模糊搜索
- ODBC api 编程
- mfc 插入 atl对象
- VCL类学习之(六) TCollectionItem