SQLServer uses stored procedures for high-performance paging. There are already many paging query methods, and I am also a member here. SQLServer has a SetRowcount setting, which means that there are already many methods for processing commands in response to the specified paging query. here I also join it as a member.
SQL Server has a Set Rowcount setting, which means that the command processing stops processing the command after responding to the specified number of rows, we can use it to implement high-performance paging query in a 10 million row-level data table. Let's talk about the implementation method:
1. assume that there is an indexed primary key field ID (integer type) in the Table. we will retrieve data by page based on this field.
2. place the page size in @ PageSize.
3. the current page number is stored in @ CurrentPage.
4. how can we make the record pointer quickly scroll to the row starting with the data we want to fetch? this is the key! With Set RowCount, we can easily implement it.
5. if we successfully scroll the record pointer to the row starting with the data we want to fetch, and then record the value of the record ID field in that row, then, using Top and conditions, we can easily get the data of a specified page. Of course, with Set RowCount, do we still use Top?
Let's see how Set Rowcount helps us:
Declare @ ID int
Declare @ MoveRecords int
-- @ CurrentPage and @ PageSize are input parameters
Set @ MoveRecords = @ CurrentPage * @ PageSize 1
-- The following two rows are used to quickly scroll to the row of the data we want to fetch and record the ID.
Set Rowcount @ MoveRecords
Select @ ID = ID from Table1 Order by ID
Set Rowcount @ PageSize
-- Most hate to reduce the trouble *, but it is used for convenience.
Select * From Table1 Where ID >=@ ID Order By ID
Set Rowcount 0
You can try it out. in a table with 100th million records, you can flip pages to 100 pages (entries per page) to see how fast it is!
Source: Nan crazy BLOG
Http://name-lh.cnblogs.com/archive/2006/03/08/346059.html
Bytes. SQL Server has a Set Rowcount setting, which means that the command processing is specified in the response...