Efficient paging with large tables in sql 2008

前端 未结 1 1938
长发绾君心
长发绾君心 2021-02-05 12:47

for tables with > 1,000,000 rows and possibly many many more !

haven\'t done any benchmarking myself so wanted to get the experts opinion.

Looked at some articl

1条回答
  •  一整个雨季
    2021-02-05 13:49

    We use row_number() to great effect and there hasn't really been any performance issues with it. The basic structure of our paginated queries looks like this:

    WITH result_set AS (
      SELECT
        ROW_NUMBER() OVER (ORDER BY ) AS [row_number],
        x, y, z
      FROM
        table
      WHERE
        
    ) SELECT
      *
    FROM
      result_set
    WHERE
      [row_number] BETWEEN a AND b
    

    It works fine for us on tables with > 1,000,000 rows.

    0 讨论(0)
提交回复
热议问题