使用场景

在项目中,涉及到数据库表变更时,可能会需要将一个或多个表中的数据迁移到另一个表中。

这时用sql去执行会很方便!

sql语句

//SQL批量插入

create table #ttableName(id int identity(1,1),customerid int,grade int,popularity int)

declare @n int,@rows int
declare @e int, @g int,@p int
insert #ttableName(customerid,grade,popularity) select Id,Grade,Popularity from Customer where Grade>0 or Popularity>0 select @rows =@@rowcount
set @n=1
while @n<=@rows
begin
select @e=customerid, @g=grade,@p=popularity from #ttableName where id=@n insert into GenericAttribute(EntityId,KeyGroup,[Key],[Value]) values(@e,'Customer','LiveLevel',@g)
insert into GenericAttribute(EntityId,KeyGroup,[Key],[Value]) values(@e,'Customer','LivePopularity',@p)
select @n=@n+1
end
drop table #ttableName

SQL Server 批量插入的更多相关文章

  1. SQL Server 批量插入数据的两种方法

    在SQL Server 中插入一条数据使用Insert语句,但是如果想要批量插入一堆数据的话,循环使用Insert不仅效率低,而且会导致SQL一系统性能问题.下面介绍 SQL Server支持的两种批 ...

  2. SQL Server 批量插入数据的两种方法(转)

    此文原创自CSDN TJVictor专栏:http://blog.csdn.net/tjvictor/archive/2009/07/18/4360030.aspx 在SQL Server 中插入一条 ...

  3. 转:SQL Server 批量插入数据的两种方法

    在SQL Server 中插入一条数据使用Insert语句,但是如果想要批量插入一堆数据的话,循环使用Insert不仅效率低,而且会导致SQL一系统性能问题.下面介绍SQL Server支持的两种批量 ...

  4. SQL Server 批量插入数据方案 SqlBulkCopy 的简单封装,让批量插入更方便

    一.Sql Server插入方案介绍 关于 SqlServer 批量插入的方式,有三种比较常用的插入方式,Insert.BatchInsert.SqlBulkCopy,下面我们对比以下三种方案的速度 ...

  5. SQL server 批量插入和更新数据

    批量插入数据 insert into A表数据库名.[dbo].A(a,b,c) (select a,b,c from B表数据库名.[dbo].B) 批量更新数据 根据身份证第二位更新性别 upda ...

  6. identity in sql server 批量插入history

    https://stackoverflow.com/questions/1920558/what-is-the-difference-between-scope-identity-identity-i ...

  7. SQL Server 批量插入数据的方法

    运行下面的脚本,建立测试数据库和表. --Create DataBase create database BulkTestDB; go use BulkTestDB; go --Create Tabl ...

  8. SQL SERVER 批量插入记录

    --create function insertData(@count as int,@tsn as bigint,@id as int) --as --begin SET IDENTITY_INSE ...

  9. SQL Server 批量插入数据

    请看代码: 创建表值参数类型: 请看代码:

随机推荐

  1. Android 使用android-support-multidex解决Dex超出方法数的限制问题

    随着应用不断迭代,业务线的扩展,应用越来越大(比如集成了各种第三方sdk或者公共支持的jar包,项目耦合性高,重复作用的类越来越多),相信很多人都遇到过如下的错误: UNEXPECTED TOP-LE ...

  2. java IO(二):字节流

    */ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...

  3. Unity 使用Plugins接入安卓SDK 基础篇

    一.须知 本帖适合对安卓一点基础都没有,有一定Unity基础.刚刚接完一个某文档很简单的渠道SDk,也当是自己总结一下. 二.Unity中的目录创建与理解. Plugins:插件目录,该目录再编译项目 ...

  4. msyql多软件连接

    菜鸟一枚 使用mysql删除数据库时,习惯性使用navicat,由于使用的是sqlyog备份的,就用sqlyog恢复数据库,结果总是报错. 用同事电脑没有问题,后来发现是用了不同的软件,导致数据库数据 ...

  5. Struts2实现文件上传和下载,多文件上传,限制文件大小,限制文件类型

    文件上传使用的包:commons-upload-xx.jar                                 commons-io-xx.jar 一.实现文件上传: 1.在表单空间中添 ...

  6. dotween tips

    涉及kill及复用的行为比较奇怪. 使用shortcut方式调用dotween时,每次调用都是增加一个新的tweener,如果该tweener控制的属性与上次调用相同时,会出现奇怪的行为,应该是多个t ...

  7. 第三方模块paramiko的使用

    "Paramiko" is a combination of the Esperanto words for "paranoid" and "frie ...

  8. linux 文件名称前后缀操作函数----取目录函数dir、取文件名称函数notdir、取后缀函数suffix、取前缀basename、加后缀函数addsuffix、加前缀addprefix、连接函数join

    1.1       文件名操作函数 下面我们要介绍的函数主要是处理文件名的.每个函数的参数字符串都会被当做一个或是一系列的文件名来对待. 1.1.1        取目录函数dir $(dir < ...

  9. linux makefile字符串操作函数 替换subst、模式替换patsubst、去首尾空格strip、查找字符串findstring、过滤filter、反过滤filter-out、排序函数sort、取单词word、取单词串wordlist、个数统计words

    1.1       字符操作函数使用 在Makefile中可以使用函数来处理变量,从而让我们的命令或是规则更为的灵活和具有智能.make所支持的函数也不算很多,不过已经足够我们的操作了.函数调用后,函 ...

  10. chrome disable-web-security 关闭安全策略 解决跨域

    Chrome 跨域访问线上接口 时间:2016-04-21 作者:zhongxia 前后端分离之后,联调的时候就会出现问题,那就是Ajax跨域问题. 跨域问题的解决方案有很多种比如常规的 后端使用CR ...