TABLESAMPLE
An introduction to TABLESAMPLE
.
If you would like a quick look at some random set of the data in a table, you
can query it using the TABLESAMPLE
keyword. As an
example, if we wanted to see a random 5% sample of the April 2017 orders we
could write a query like this:
SELECT *
FROM apr_2017_orders TABLESAMPLE(5)
And the data we would get back would look something like this:
sales_agent | account | product | order_value | create_date |
---|---|---|---|---|
Boris Faz | Betasoloin | GTX Plus Basic | 992 | 2017-04-03 |
Anna Snelling | dambase | GTX Plus Pro | 5060 | 2017-04-01 |
Reed Clapper | Bioplex | GTX Plus Pro | 5095 | 2017-04-12 |
Violet Mclelland | Gekko & Co | MG Special | 45 | 2017-04-07 |
Darcel Schlecht | Rundofase | MG Special | 64 | 2017-04-14 |
Donn Cantrell | Plussunin | MG Advanced | 3655 | 2017-04-15 |
Kary Hendrixson | Plexzap | GTX Plus Pro | 6154 | 2017-04-07 |
Kary Hendrixson | Cheers | GTXPro | 4756 | 2017-04-12 |
Zane Levy | Dalttechnology | GTXPro | 4168 | 2017-04-12 |
Anna Snelling | Warephase | GTX Basic | 596 | 2017-04-08 |
Boris Faz | Zotware | MG Special | 59 | 2017-04-15 |
Corliss Cosme | Konex | GTX Plus Pro | 5684 | 2017-04-15 |
Darcel Schlecht | Gogozoom | GTXPro | 4413 | 2017-04-15 |
The results returned from every TABLESAMPLE
query would differ unless the query returned all of the data because every time the query was run it would select a different sample of the data to return.
Next up: Metadata Tables
An introduction to the metadata tables: Schemata
, Tables
, Views
and Tablecolumns
.