Depending on your needs, TABLESAMPLE
will get you nearly as random and better performance.this is available on MS SQL server 2005 and later.
TABLESAMPLE
will return data from random pages instead of random rows and therefore deos not even retrieve data that it will not return.
On a very large table I tested
select top 1 percent * from [tablename] order by newid()
took more than 20 minutes.
select * from [tablename] tablesample(1 percent)
took 2 minutes.
Performance will also improve on smaller samples in TABLESAMPLE
whereas it will not with newid()
.
Please keep in mind that this is not as random as the newid()
method but will give you a decent sampling.
See the MSDN page.