The Other Way of Generating Test Data

In my last tip, I wrote about getting rows in random order, and mentioned that that was a useful technique for generating
test data.

However, I neglected to mention that my reason for wanting randomly selected rows was because I knew that there were
patterns in my data which meant that I couldn't use "the other way of generating test data".

For many data sets, one can obtain a representative sample by selecting every 10th or every 100th record.

SELECT MyField FROM MyTable WHERE MyTable.ID%100=0

NB: % is MS SQL Server's modulo operator. Oracle users
can use the function "MOD".

If the query involves more than one table, it makes sense to choose a table which is at the "one" end of all the one-to-many relationships, select every 100th record from that table, and select all the records which are related to that subset.

For example, the following query will select every 100th customer, and all of their orders.

SELECT Customer.*, Order.*, OrderDetail.*
FROM Customer, Order, OrderDetail, Product
WHERE Customer.CustomerID=Order.CustomerID
AND Order.OrderID=OrderDetail.OrderID
AND CustomerID%100=0


Adelle.

 

Home About the Author Copyright © 2001 Adelle Hartley