我正在回答问题
hereabouts并在发布之前启动我的SSMS测试一个小查询,但得到了一些奇怪的结果.这是查询:
UPDATE Person SET Pos_X = Rand(),Pos_Y = Rand(id) SELECT ID,Surname,Forename,Pos_X,Pos_Y FROM Person
以下是结果集:
1 Bloggs Fred 0.332720913214171 0.713591993212924 2 Doe Jane 0.332720913214171 0.713610626184182 3 Smith Mary 0.332720913214171 0.71362925915544 4 Jones Martha 0.332720913214171 0.713647892126698 5 Jones Martha 0.332720913214171 0.713666525097956 6 Jones Martha 0.332720913214171 0.713685158069215 7 Jones Martha 0.332720913214171 0.713703791040473 8 Jones Martha 0.332720913214171 0.713722424011731 9 Jones Martha 0.332720913214171 0.713741056982989
正如我所预期的那样没有种子的兰德在每一行都会得到相同的结果,但我希望rand与种子(albiet只是数字1到9)会比0.0002之内的有序列表好一点!
你有同感吗?这听起来像是可以找出粗心大意的东西.
我相信这是相关的:
@@Version = 'Microsoft sql Server 2005 - 9.00.5000.00 (Intel X86) Dec 10 2010 10:56:29 Copyright (c) 1988-2005 Microsoft Corporation Express Edition on Windows NT 6.1 (Build 7601: Service Pack 1) '
解决方法
RAND (Transact SQL):
Returns a pseudo-random float value from 0 through 1,exclusive.
和:
Repetitive calls of RAND() with the same seed value return the same results.
(强调我的)