what is tablesample() function

Posted by Mcadeepuraj under Sql Server category on | Points: 40 | Views : 2393
suppose we want the table with large data for view purpose, we can use tablesample() function
suppose there is a table with 3000 row, we dont want to view all record , but we want to view column name with some simple data
then we can write

use adventureworks

select * from production.Product tablesample(10 percent)

we can also use rows instead of percentage

select * from production.Product tablesample(10 rows)

Comments or Responses

Posted by: T.saravanan on: 5/22/2011 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi Deepak Kumar,

Nice info.But kindly post your code inside the code tag.

Posted by: Bugwee on: 5/23/2011 Level:Starter | Status: [Member] | Points: 10

What sql server you are using? The given snippet unable to execute using sql server 2000.

Posted by: Jayeshl on: 6/24/2011 Level:Starter | Status: [Member] | Points: 10
hi friend,
thanks to post this code here.
i have one concern for this query
i have one Employee table and it contains 2500 records..
when i tried this example on that table with
select * from Employee tablesample(10 rows)

so it returns 34 rows
than again i tried to run same query at that time it returns 25 rows
i again tried for same query at that time it returns nothing..

can you tell me where i am wrong to fetch records from table
and one more thing which is noticeable that every time it returns rows in random manner like empid between 1500 to something and another time empid 1250 to some records

so plz explain me what is the core logic for this.


jayesh l

Login to post response