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. 系列文章--SharePoint 2013 Designer 入门教程

    SharePoint的使用中,SharePoint Designer是非常重要的工具,我们可以通过Designer设计页面.母版页,维护.管理站点,也可以定制列表表单.数据视图,设计工作流等等.下面总 ...

  2. ORACLE 11G负载均衡测试

    Oracle 11g R2中,引入了SCAN(Single Client Access Name)的特性.该特性的好处在于,在数据库与客户端之间,添加了一层虚拟的服务层,就是所谓的SCAN IP以及S ...

  3. (转)从android一个apk中启动第三方apk应用

    从android一个apk中启动第三方apk应用 我们在开发中,经常遇到遇到在一个apk中要去运行另外一个apk,就像我们windows一样,搞一个快捷方式一样,那怎么实现呢? 问题的核心点在于我们要 ...

  4. C语言通过地址传递参数

    // 正确 #include <stdio.h> struct para { int a; int b; }; struct para test = { .a = , .b = , }; ...

  5. 字符串(二)(PHP)

    1.大段文本在PHP中应该如果表示? 答: <?php $str = <<<aaa hello word; fjasdflj fjslad aaa;date_sub() aaa ...

  6. 蓝桥杯 算法训练 ALGO-93 反置数

    算法训练 反置数   时间限制:1.0s   内存限制:512.0MB 问题描述 一个整数的“反置数”指的是把该整数的每一位数字的顺序颠倒过来所得到的另一个整数.如果一个整数的末尾是以0结尾,那么在它 ...

  7. java代码=========这个代码还是有问题的。不能实现功能呀

    有问题的代码: package com.a.b; import javax.swing.*; import java.awt.Color; import java.awt.event.*; impor ...

  8. java代码Calendar类

    总结:时间类Calendar.类代表当前时 Calendar c=Calendar.getInstance();,,Calendar是抽象类.Calendar的构造方法是私有的,API提供了getIn ...

  9. Python中常用模块一

    random模块 import random # 应用数学计算 print(random.random()) # 取随机小数 范围是 0-1之间 # 应用抽奖 , 彩票 print(random.ra ...

  10. Hadoop IO基于文件的数据结构详解【列式和行式数据结构的存储策略】

    Charles所有关于hadoop的文章参考自hadoop权威指南第四版预览版 大家可以去safari免费阅读其英文预览版.本人也上传了PDF版本在我的资源中可以免费下载,不需要C币,点击这里下载. ...