All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
SQL Server 2005下的分页SQL_[SQL Server教程]
More,Effective,C++之智能指针_[Asp.Net教程]
Delphi主菜单组件(TMainMenu)技巧
C#网络应用编程基础练习题与答案(二)_.net资料_编程技术
安装并使用phpMyAdmin管理MySQL数据库_[PHP教程]
asp.net,URL重写(URLRewriter),之简化版_.net资料_编程技术
C#中正则表达式进行忽略大小写的字符串替换_[Asp.Net教程]
VS,2008和.NET,3.5,Beta2常见问题的解决方案_.net资料_编程技术
ASP.Net下两种全局变量的设置和读取方法_[Asp.Net教程]
C#中GroupBox控件应用实例
Reading number is top 10 pictures
China's first snake village3
Female model behind the bitterness, often being overcharged1
Li Zongrui hunting video screenshots1
Black and white also sexy--YanLiu1
A man's favorite things16
Sexy women in 2013--2
More attractive than sora aoi4
重口味人造肉
Beautiful Japanese beauty(漂亮的日本美女)
The little woman's bright wire3
Download software ranking
徐若瑄成名作“魔鬼天使”
Boxer Classic video3
Proficient in Eclipse
jBuilder2006
Unix video tutorial13
Ashlynn Video3
Rio big adventure
Boxer's Top ten classic battle9
Professional killers2 for Android
Tram sex maniac 2 (H) rar bag16
归海一刀 published in(发表于) 2014/2/3 6:43:47 Edit(编辑)
如何利用SQL查询返回庞大的整数序列表_[SQL Server教程]

如何利用SQL查询返回庞大的整数序列表_[SQL Server教程]

如何利用SQL查询返回庞大的整数序列表_[SQL Server教程]

WITH Digits AS (
SELECT 0 as Number
UNION SELECT 1
UNION SELECT 2
UNION SELECT 3
UNION SELECT 4
UNION SELECT 5
UNION SELECT 6
UNION SELECT 7
UNION SELECT 8
UNION SELECT 9
)
SELECT
(d5.Number * 100000)
+ (d4.Number * 10000)
+ (d3.Number * 1000)
+ (d2.Number * 100)
+ (d1.Number * 10)
+ d0.Number as Number
FROM
Digits AS d0
, Digits AS d1
, Digits AS d2
, Digits AS d3
, Digits AS d4
, Digits AS d5


在SQLServer 2005中,这个SQL返回一个包含1000000条记录的结果集,从0到999999。
这条语句利用了SQL2005的新功能:CTE (Common Table Expression)
如果当前的数据库是SQL 2000或其他不支持CTE的数据库,则可以将WITH部分的SQL定义为一个视图。


CREATE VIEW .[Digits] AS
SELECT 0 AS Number
UNION SELECT 1
UNION SELECT 2
UNION SELECT 3
UNION SELECT 4
UNION SELECT 5
UNION SELECT 6
UNION SELECT 7
UNION SELECT 8
UNION SELECT 9;
CREATE VIEW [MillionNumbers] AS
SELECT
SELECT (d5.Number * 100000)
+ (d4.Number * 10000)
+ (d3.Number * 1000)
+ (d2.Number * 100)
+ (d1.Number * 10)
+ d0.Number) as Number
FROM
Digits AS d0
, Digits AS d1
, Digits AS d2
, Digits AS d3
, Digits AS d4
, Digits AS d5;


我们可以用这个方法来生成大批量的测试数据。如:


INSERT INTO MyTest (RecordId, RecordIndex)
SELECT newid(), Number FROM MillionNumbers


用此方法插入数据,要比利用循环快很多倍。







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.