1.分批更新数据库

declare @x int
set @x=1
while(@x<=51)
begin
begin tran
update UserFavorite set UserFavorite.firstpublishtime = product.lastpublishtime
from UserFavorite,product where UserFavorite.productid = product.id
and UserFavorite.id between (@x-1)* 10000 and @x*10000
commit tran
set @x=@x+1
WAITFOR DELAY '00:00:30'; --等待5秒
end

2.批量更新收藏表

USE [TianYi]
GO
/****** Object:  StoredProcedure [dbo].[UpdateUserFavoriteByProductid]    Script Date: 01/23/2015 13:28:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
  ALTER proc [dbo].[UpdateUserFavoriteByProductid]
  as
  begin
   create table #temp2
   (
     id int identity(1,1),
     productid int,
     LastPublishTime datetime
   )
  
   declare @ufpage int --@ufnum/10000
   declare @ufn int --收藏表循环次数
    --取出所有要更新的系列下的所有产品
     insert into #temp2 select ID,LastPublishTime from Product where serieID in(select distinct serieID from Product where IsCollectionOperate=1)
                set @ufn=1
                set @ufpage=1000--假设有10000000条数据
                while @ufn<=@ufpage
                 begin
                    begin tran
update UserFavorite set  UserFavorite.isSeriesUpdate=1,UserFavorite.ispop=1,
UserFavorite.FirstPublishTime = #temp2.LastPublishTime
from UserFavorite  inner join #temp2  on  UserFavorite.productID=#temp2.productid
where UserFavorite.ID between (@ufn-1)*10000 and @ufn*10000
                    set @ufn=@ufn+1
                    WAITFOR DELAY '00:00:02'; 
                     commit tran
                 end
                  --更新后重置更新状态
               update Product set IsCollectionOperate=0 where Id in(select productid from #temp2)
     
     truncate table #temp2 --删除原表数据,并重置自增列
     insert into #temp2 select ID,LastPublishTime from Product where Id in(select distinct productID from ProductAudio where IsCollectionOperate=1)
                set @ufn=1
                set @ufpage=1000--假设有10000000条数据
                while @ufn<=@ufpage
                 begin
                    begin tran
                      update UserFavorite set UserFavorite.isread=1,UserFavorite.ispop=1,
UserFavorite.FirstPublishTime = #temp2.LastPublishTime
from UserFavorite  inner join #temp2  on  UserFavorite.productID=#temp2.productid
where UserFavorite.ID between (@ufn-1)*10000 and @ufn*10000
                    set @ufn=@ufn+1
                    WAITFOR DELAY '00:00:02'; 
                     commit tran
                 end
                  update ProductAudio set IsCollectionOperate=0 where productid in (select productid from #temp2)
    
 end
-------------------------------------------------------------------------------------------------------------------------
 
 3. 批量更新递增列

--申明一个游标
DECLARE MyCursor CURSOR
FOR select id from productaudio where productid = 756407 order by linkurl

declare @x int
set @x=1

--打开一个游标
OPEN MyCursor

--循环一个游标
DECLARE @id int
FETCH NEXT FROM MyCursor INTO @id
WHILE @@FETCH_STATUS =0
BEGIN
update productaudio set audioname = @x where id = @id
set @x=@x+1
FETCH NEXT FROM MyCursor INTO @id
END

--关闭游标
CLOSE MyCursor
--释放资源
DEALLOCATE MyCursor

Sql语句摘要的更多相关文章

  1. 使用Hive或Impala执行SQL语句,对存储在HBase中的数据操作

    CSSDesk body { background-color: #2574b0; } /*! zybuluo */ article,aside,details,figcaption,figure,f ...

  2. 使用Hive或Impala执行SQL语句,对存储在Elasticsearch中的数据操作(二)

    CSSDesk body { background-color: #2574b0; } /*! zybuluo */ article,aside,details,figcaption,figure,f ...

  3. 使用Hive或Impala执行SQL语句,对存储在Elasticsearch中的数据操作

    http://www.cnblogs.com/wgp13x/p/4934521.html 内容一样,样式好的版本. 使用Hive或Impala执行SQL语句,对存储在Elasticsearch中的数据 ...

  4. 使用BAT批处理执行sql语句的代码

    使用BAT批处理执行sql语句的代码 有时候需要执行一些Sql语句时,不想开企业管理器,或者是发给客户执行但那边又不懂代码,这时就可以用下面方法 1.把待执行Sql保存在一个文件,这里为2011022 ...

  5. Python与开源GIS:在OGR中使用SQL语句进行查询

    摘要: 属性选择与空间选择都可以看作是OGR内置的选择功能,这两种功能可以解决大部分实际中的问题.但是也有这种时候,就是进行查询时的条件比较复杂.针对这种情况,OGR也提供了更加灵活的解决方案:支持使 ...

  6. 看懂SqlServer查询计划 SQL语句优化分析

    转自 http://www.cnblogs.com/fish-li/archive/2011/06/06/2073626.html 阅读目录 开始 SQL Server 查找记录的方法 SQL Ser ...

  7. 《万能数据库查询分析器》实现使用SQL语句直接高效地访问文本文件

    <万能数据库查询分析器>实现使用SQL语句直接高效地访问文本文件 马根峰 (广东联合电子服务股份有限公司, 广州 510300) 摘要    用SQL语句来直接访问文本文件?是在做梦吗? ...

  8. 软件开发顶尖高手的杀手锏SQL语句

                  软件开发顶尖高手的杀手锏SQL语句                                                                     ...

  9. 由一条sql语句想到的子查询优化

    摘要:相信大家都使用过子查询,因为使用子查询可以一次性的完成很多逻辑上需要多个步骤才能完成的SQL操作,比较灵活,我也喜欢用,可最近因为一条包含子查询的select count(*)语句导致点开管理系 ...

随机推荐

  1. nginx中在超全局变量$_SERVER中增加变量

    业务中可能会用到一些自定义的超全局变量,需要在nginx中生成的,比如,每次nginx请求的id,可以在nginx中配置 如: location ~ \.php$ { root           / ...

  2. setContentHuggingPriority和setContentCompressionResistancePriority的使用

    当两个UILabel并排显示时,如何设置约束,让 leftLB 和 rightLB 正常显示就很重要了. 方案1:左右两个Label的宽度相同,则约束设置如下: //添加标题约束,左边的label [ ...

  3. subline自定义快捷键

    由于感觉原始subline的运行快捷键ctrl+b不是很方便,尝试修改,方法如下: 打开首选项 --> 快捷键设置 Key Bindings -Default //这个表示系统默认的快捷键.Ke ...

  4. poj 3046 Ant Counting——多重集合的背包

    题目:http://poj.org/problem?id=3046 多重集合的背包问题. 1.式子:考虑dp[ i ][ j ]能从dp[ i-1 ][ k ](max(0 , j - c[ i ] ...

  5. (转)android - anim translate中 fromXDelta、toXDelta、fromYDelta、toXDelta属性

    2012-03-23 15:51 16144人阅读 评论(5) 收藏 举报 android <set xmlns:android="http://schemas.android.com ...

  6. VCS (版本控制系统)

    1.什么是VCS? 版本控制系统(version control system),是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统.版本控制系统不仅可以应用于软件源代码的文本文件, ...

  7. composer的安装和使用 学习日志

    如果你做为一个phper,没有用过composer,那你真的不是一个合格的开发者.那么就来记录一下composer的学习日志 下面分享几个学习源头: composer中文网站:https://www. ...

  8. 控制台执行CI方法

    执行方法:进入到ci放入口文件目录 执行 php index.php 控制器 方法 #php index.php home index

  9. further occurrences of HTTP header parsing errors will be logged at DEBUG level.

    1.   获取参数Json的值为null String json=request.getParameter("Json"); 首先检查是否有下面的东东, 信息: Error par ...

  10. 华为公司内部培训资料_介绍RTSP的消息、信令等

    https://wenku.baidu.com/view/b10415dabd64783e08122b9c.html