derekr 43208 (3/27/2012)
Hi GuysBy declaring the variables as below - Will that guarantee that every number generated is Unique?
SELECT @NumberOfRows = 10000000,
@StartValue = 1,
@EndValue = 10000000,
@Range = @EndValue - @StartValue + 1
Thanks
Yes for the rownumber generator, No for the random number generator.
If you want unique but randomly sorted numbers, it will involve a sort (which will be time consuming for as many rows as you've identified) using NEWID() to sort on.
WITH
cteRowNumberGenerator AS
(--==== Prevents sorting all the rows of the cross join.
SELECT TOP (1000) --Put your desired number here
UniqueNumber = ROW_NUMBER() OVER (ORDER BY (SELECT NULL))
FROM sys.all_columns ac1
CROSS JOIN sys.all_columns ac2
)--==== Randomly sorts just the numbers generated from above.
SELECT UniqueNumber
FROM cteRowNumberGenerator
ORDER BY NEWID()
;
--Jeff Moden
Change is inevitable... Change for the better is not.