zoukankan      html  css  js  c++  java
  • SQL Server 批量插入

    使用场景

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

    这时用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
    
  • 相关阅读:
    关于javascript获取页面高度宽度
    regexp_substr在oracle9i的替换方案
    iOS-数据存储
    iOS-导入XMPP框架
    iOS-WWDC
    iOS-在Xcode中使用Git进行源码版本控制(转)
    iOS-AFN
    iOS-网络基础
    iOS-UIDynamic
    iOS-动画
  • 原文地址:https://www.cnblogs.com/zhubangchao/p/7741526.html
Copyright © 2011-2022 走看看