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. Javascript 原型链资料收集

    Javascript 原型链资料收集 先收集,后理解. 理解JavaScript的原型链和继承 https://blog.oyanglul.us/javascript/understand-proto ...

  2. bzoj 2119 股市的预测 —— 枚举关键点+后缀数组

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2119 思路就是对于这个形如 ABA 的串,枚举 A 的长度,并按照长度分出几块,找到一些关键 ...

  3. 搭建Ganglia乱码及其他问题总汇

    搭建Ganglia乱码及其他问题 搭建完Ganglia监控后图像显示正常,但是文字却显示都是小方框,最后确定是由于系统缺少字体导致的, /usr/share/fonts/  Centos默认存放字体的 ...

  4. 控制台执行CI方法

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

  5. 1136 A Delayed Palindrome

    题意:略. 思路:大整数相加,回文数判断.对首次输入的数也要判断其是否是回文数,故这里用do...while,而不用while. 代码: #include <iostream> #incl ...

  6. CP干货:手机游戏上线前需要准备什么

    转自:http://www.gamelook.com.cn/2015/09/229002 游戏研发完成后游戏该怎样推广?如何找渠道?推广时需要注意什么?下面给大家介绍一下具体流程,可能每个公司的上线流 ...

  7. C语言中的未初始化变量的值

    C语言中未初始化的变量的值是0么 全局变量 .静态变量初始值为0局部变量,自动变量初始值随机分配 C语言中,定义局部变量时如果未初始化,则值是随机的,为什么? 定义局部变量,其实就是在栈中通过移动栈指 ...

  8. float型数据与字节数组的转化

    float型数据与字节数组的转化 字节(float)浮点数为例. 一.C语言 转化常见的方法有: 1.强制指针类型转换. [html] view plain copy //转换float数据到字节数组 ...

  9. 使用K2时提示未能加载文件或程序集Microsoft.IdentityModel等

    转:http://www.cnblogs.com/dannyli/archive/2012/10/15/2724931.html K2安装成功后,打开workspace管理流程时报错如下图: 未能加载 ...

  10. 视频x264编码浅析

    声明 x264_param_t 结构体变量: x264_param_t params; x264_param_default_preset(&params, "ultrafast&q ...