I want to get some random records from db. There is two solution for this :
1- Using TABLESAMPLE for getting data from db directly.
2- Write a method In my application for doing this. In this method we generate multiple random number and get data like this :
select * from db where ID = @RandomNumber
if this ID does not exist, I pass a new number.
Now which one has better performance?
According to the documentation for TABESAMPLE you shouldn’t use it if you “really want a sample of individual rows”:
Either way, given the potentially endless number of requests you could make by passing in @RandomNumber (in theory the first 1000 requests you make might return nothing), the better approach is to limit the resultset on the server.