In my Design section today, I ranted a bit about automated testing and a trend I have noticed to avoid directly accessing a database for that testing. It didn't start out to be a rant, but rather a tip about grabbing a random SQL record.
Using an ORDER BY NewID() clause, you can either randomly order your data, or grab a random single row. I use the single row method to grab data for testing so I am not always testing the same value, or occassionally the random order when I am searching for a particular set of data using a cursor for really complicated testing. Here's the usage:
Random order:
SELECT * FROM Authors ORDER BY NewID()
Single Random Record:
SELECT TOP 1 * FROM Authors ORDER BY NewID()
Powered by: newtelligence dasBlog 2.3.9074.18820
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2012, © Copyright 2010
E-mail