Friday , April 19 2024

Random Data Selection(TABLESAMPLE)

 

Did you know that TABLESAMPLE can be used after FROM to select random data from a table?

For example you can use the following: 

This command is quite unstable. When you run this query to return 2% of the records in the table, a different number of results will be returned each time.

 

You can also use this command in the following way:

But this query will not return 500 records. It will return between 300 and 800 records.

 

Another use is as follows:

With REPEATABLE option, you can specify a “bigint” value. So that the query returns the same result every time. But the result set returned by the query will change when the records in the table are changed or the bigint value that you specify changes.

If an INSERT, UPDATE, DELETE, or Index Rebuilding operation is performed, a different set will return even if the value you give in REPEATABLE is the same.

Loading

About Ekrem Önsoy

The original article was written in Turkish by Ekrem Önsoy and translated to English by dbtut with the consent of the author. The copyright of the article belongs to the author. The author shall not be liable in any way for any defect caused by translation.

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories