View Full Version : Using ORDER BY NEWID()
02-28-2003, 10:51 AM
I'm looking at using ORDER BY NEWID() in my sql statement to generate random records from a database, like this:
"SELECT TOP 3 * FROM tblTable ORDER BY NEWID()"
Is this an efficient method for selecting from tables with less than 5,000 rows, or can anyone suggest a better approach.
DB is MS SQL Server 2000.
02-28-2003, 03:35 PM
It seems to work ok but as for efficiency you'll have to use the performance tools to see if it's creating a burden on the server.
03-01-2003, 02:25 AM
If you've got less than 5,000 rows, I think pretty much anything will work, unless you've got other databases on the server that are getting hit hard.
That isn't very much data as far as SQL Server is concerned - but it's still a good idea to do things right - so I'd definitely look at the server performance tools as Roy suggested.
03-03-2003, 08:52 AM
Thanks guys, this does fit with what I was thinking. Using the NEWID() may be inefficient for very large tables as the db has to generate a unique ID for each row, but as you say 5,000 is few.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.