博客日历
2024年05月 | ||||||
一 | 二 | 三 | 四 | 五 | 六 | 七 |
29 | 30 | 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 | 1 | 2 |
存档
2024年03月 04月 05月 2021年
01月 02月 11月 12月 2020年
02月 03月 04月 05月 06月 07月
09月 2018年
09月 2017年
01月 02月 07月 2016年
01月 04月 07月 08月 11月 12月
2015年
01月 02月 03月 05月 09月 10月
11月 2014年
01月 02月 03月 04月 05月 06月
07月 08月 09月 10月 11月 12月
2013年
01月 02月 03月 04月 05月 06月
07月 08月 09月 10月 11月 12月
2012年
01月 02月 03月 04月 05月 06月
07月 08月 09月 10月 11月 12月
2011年
01月 02月 03月 04月 05月 06月
07月 08月 09月 10月 11月 12月
2010年
01月 02月 03月 04月 05月 06月
07月 08月 09月 10月 11月 12月
2009年
03月 04月 05月 06月 07月 08月
09月 10月 11月 12月
不使用游标遍历记录集
declare @startTime datetime
set @startTime = getdate()
if object_id('tempdb..#tmpTable') is not null
drop table #tmpTable;
declare @RowCount int = 0;
select ROW_NUMBER() over(ORDER BY ID ASC) as RowNumber,名称 into #tmpTable from 客户;
set @RowCount = @@ROWCOUNT;
create clustered index index_tmp On #tmpTable(RowNumber ASC) with FILLFACTOR = 100;
declare @CustName varchar(50);
declare @iRow int = 0;
while(@iRow < @RowCount)
begin
set @iRow = @iRow + 1;
select top 1 @CustName=名称 from #tmpTable where RowNumber = @iRow ;
end;
drop table #tmpTable;
select datediff(ms,@startTime,getdate()) as '耗时','毫秒' as '单位'
不过,测试发现此方法和加了 FAST_FORWARD 的游标性能基本一致。
10000条记录,在T3400,SSD 830 Series,SQL2008上需要的时间都是200ms。
参考文章中提到的其他方法则远不如游标的性能,可能需要进一步验证。
参考:
http://support.microsoft.com/kb/111401
http://www.searchdatabase.com.cn/showcontent_24030.htm
http://wenku.baidu.com/view/94656feb172ded630b1cb6a6.html
10000条记录,在T3400,SSD 830 Series,SQL2008上需要的时间都是200ms。
参考文章中提到的其他方法则远不如游标的性能,可能需要进一步验证。
参考:
http://support.microsoft.com/kb/111401
http://www.searchdatabase.com.cn/showcontent_24030.htm
http://wenku.baidu.com/view/94656feb172ded630b1cb6a6.html
上一篇: 自动生成ADO连接字符串的方法
下一篇: 用RTL2832U+E4000电视棒体验软件无线电
分类:数据库 查看次数:4768 发布时间:2013/3/1 11:35:11