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 反向代理与负载均衡详解

    序言 Nginx的代理功能与负载均衡功能是最常被用到的,关于nginx的基本语法常识与配置已在Nginx 配置详解中有说明,这篇就开门见山,先描述一些关于代理功能的配置,再说明负载均衡详细. Ngin ...

  2. sql for 存储过程格式

    sql DELIMITER && CREATE PROCEDURE test2() BEGIN DECLARE i INT; ; DO ')); ; END WHILE; END; & ...

  3. str_split的用法(PHP学习)

    str_split的用法: 先看看PHP手册是怎么说的 array str_split ( string $string [, int $split_length = 1 ] ) str_split返 ...

  4. DHCP(三)

    选择阶段:即DHCP客户端选择IP地址的阶段.如果有多台DHCP服务器向该客户端发来DHCP Offer报文,客户端只接受第一个收到的DHCP Offer报文,然后以广播方式发送DHCP Reques ...

  5. C#三层架构实例

    对于三层的概念查也查了,看也看了,下面是我找的一个关于三层的简单实例,真正看一下它是如何具体实现的. 我们先来一起看看 实体类-Model 实质:实体类就是在完成数据库与实体类对应的功能,一个类是一张 ...

  6. mssql server修改数据库文件位置 此种方法暂未测试成功

    --查看当前的存放位置 select database_id,name,physical_name AS CurrentLocation,state_desc,size from sys.master ...

  7. Vue 简单的总结二

    表单输入绑定 数据双向绑定 v-model 绑定相同的属性 当属性变化绑定的标签内容也跟着变化 v-model 只能应用像在input textare select 标签 v-model.lazy 懒 ...

  8. RabbitMQ操作方法

    /// <summary> /// 消费者(消息) /// </summary> public class CustmerMq { /// <summary> // ...

  9. MySQL高可用MHA实战

    MySQL高可用架构MHA介绍 简介: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职 ...

  10. webRTC peerconnection_client demo创建VS工程

    编译了webRTC Windows源码之后,想使用编译出来的库写一个demo出来,但是又不知到怎么下手.就想通过源码中带的示例peerconnection_client和peerconnection_ ...