I just discovered a new SELECT clause that has been added to T-SQL in SQL Server 2005. TABLESAMPLE can be used to return a sampling of rows (either a fixed number or a specified percent of the table rows). Here is how it is used:
/* Get a sample 5 rows */
SELECT *
FROM table
TABLESAMPLE (5 ROWS)
/* Get a sample 10 percent of rows */
SELECT *
FROM table
TABLESAMPLE (10 PERCENT)
It is worth noting that you may not get the exact number of rows that you’d expect. Sampling occurs by table page, and the number of rows in a page can vary.
Leave a Reply