sqlserver小批量导数据
GO
/****** Object: StoredProcedure [dbo].[proc_insert] Script Date: 01/09/2015 18:44:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[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 =36 then 'case when '+
a.name+' is null then ''NULL'' else '+'''''''''+'+'convert(varchar(36),'+
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
sqlserver小批量导数据的更多相关文章
- sqlserver存储过程批量插入数据
在系统中经常会遇到向数据库中批量插入数据情况,存储过程中没有数组,只有通过字符串分割循环插入,下面是一个本人研究的一个例子: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 c ...
- 利用DataTable快速批量导数据
DataSet ds = new DataSet(); using (SqlConnection conn = new SqlConnection(@"data sou ...
- C#批量插入数据到Sqlserver中的四种方式
我的新书ASP.NET MVC企业级实战预计明年2月份出版,感谢大家关注! 本篇,我将来讲解一下在Sqlserver中批量插入数据. 先创建一个用来测试的数据库和表,为了让插入数据更快,表中主键采用的 ...
- C#批量插入数据到Sqlserver中的三种方式
本篇,我将来讲解一下在Sqlserver中批量插入数据. 先创建一个用来测试的数据库和表,为了让插入数据更快,表中主键采用的是GUID,表中没有创建任何索引.GUID必然是比自增长要快的,因为你生 成 ...
- 【转载】C#批量插入数据到Sqlserver中的三种方式
引用:https://m.jb51.net/show/99543 这篇文章主要为大家详细介绍了C#批量插入数据到Sqlserver中的三种方式,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 本篇, ...
- sqlserver 中批量删除\r\n 换行符
从Excel中向sqlserver 中批量粘贴数据时 可能会粘贴进去换行符 \r\n 这时候在查询时候是看不见的 只有把该字段赋值到‘’中才能发现换行. 批量替换语句: update [表名]set ...
- SQLServer使用表值参数,高性能批量插入数据
记得前段时间帮同事写了个解析账号并入库的小工具,来批量导入账号信息,账号量相当大,程序每读取一条记录便执行一次insert来插入数据,整整跑了一下午才把账号全部入库. 今天又接到同事类似的需求,不过这 ...
- SqlServer 利用游标批量更新数据
SqlServer 利用游标批量更新数据 Intro 游标在有时候会很有用,在更新一部分不多的数据时,可以很方便的更新数据,不需要再写一个小工具来做了,直接写 SQL 就可以了 Sample 下面来看 ...
- 自由导入你的增量数据-根据条件将sqlserver表批量生成INSERT语句的存储过程实施笔记
文章标题: 自由导入你的增量数据-根据条件将sqlserver表批量生成INSERT语句的存储过程增强版 关键字 : mssql-scripter,SQL Server 文章分类: 技术分享 创建时间 ...
随机推荐
- IE8提示console未定义
在开发的过程中由于调试的原因,在代码中加入console.info("xxxx"),而未进行删除 在IE8下测试该代码所在的页面报错,如下: 需要注意的是,使用console对象查 ...
- [转载]Sleep(x)的使用和sleep(0)作用解析
链接:http://blog.csdn.net/m_leonwang/article/details/28434383 假设现在是 2012-12-16 3:37:40,如果我调用一下 Thread. ...
- Linux驱动多线程 - 互斥量
1.内核多线程相关内容 1.1 头文件#include <linux/kthread.h> 1.2 定义/初始化变量 struct mutex SPI_work; /*定义互斥体*/ mu ...
- Java-API-POI-Excel:XSSFWorkbook Documentation
ylbtech-Java-API-POI:XSSFWorkbook Documentation 1.返回顶部 1. org.apache.poi.xssf.usermodel Class XSSFWo ...
- Linux常用的编辑保存退出命令
Vi Vim进入编辑后退出 按ESC后 1.保存退出 :wq :x 最快捷的方法:直接按shift+zz,或者切换到大写模式按ZZ,就可以保存退出了,即是按2下大写的Z.区别::wq 强制性写入文件并 ...
- 通过在Oracle子表外键上建立索引提高性能
根据我的经验,导致死锁的头号原因是外键未加索引(第二号原因是表上的位图索引遭到并发更新).在以下两种情况下,Oracle在修改父表后会对子表加一个全表锁: 1)如果更新了父表的主键(倘若遵循关系数据库 ...
- 11-09SQLserver 基础-数据库之汇总练习45题
设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1-2的表 ...
- mysql权限表
http://blog.csdn.net/zhangliangzi/article/details/51882710
- docker 笔记(6)网络
docker network ls 默认docker安装时会创建3个网络 none网络 one 网络就是什么都没有的网络.挂在这个网络下的容器除了 lo,没有其他任何网卡.容器创建时,可以通过 - ...
- LinearLayout线性布局搭配权重属性的使用
在开发中,我们是通过布局来完成应用界面的搭配的,通过各种布局,我们可以完成各种复杂的界面设计.而LinearLayout也就是我们说的线性布局,这个比较简单而且使用很广泛的一种布局.下面我们通过一个D ...