SQL Server Performance

Shorten large Recordsets ?

Discussion in 'T-SQL Performance Tuning for Developers' started by marky, Nov 11, 2002.

  1. marky New Member

    hello,

    what are the best ways to shorten large Recordsets, besides:

    - select top X

    and how can we manage to give always a random (as random) set of data on such a select back to the client ?

    thanks a lot for tips, mr
  2. bradmcgehee New Member

    I am not sure exactly what are you asking

    If you are wanting to reduce the amount of data in a recordset, and you don't care if they are the (TOP), then the best way to reduce them is to use a very restrictive WHERE clause and only return those columns that you must have returned, and no more.

    If you want the (TOP) records, of course, as you have mentioned, TOP can be used. Why don't you want to use this option? Alternatively, you could use a very restrictive WHERE clause and then use an ORDER BY to get the order you want.

    There are several ways to get random data. Here is one option. Assuming that the number of records you want returned are not too many, you first, in a stored procedure, create a set of random selections of a key column, using the random function, then use these to SELECT from the the table using dynamic SQL code. You could also use a TEMP table or a cursor, but both of these could present performance issues.

    Anyone else got any good ideas?



    ------------------
    Brad M. McGehee
    Webmaster
    SQL-Server-Performance.Com
  3. burbakei New Member

    a bettre way
    generate an integer random number by RAND function and then

    SET @@ROWCOUNT @Rnd

    SELECT *
    FROM RandTable
    ORDER BY NEWID()

    SET @@ROWCOUNT 0

Share This Page