OK, we first create a database: Data_test, and create a table in this database: tb_testtable
Create DATABASE Data_test--Creating databases Data_test
Go
Use Data_test
Go
CREATE TABLE Tb_testtable--Creating tables
(
ID int identity (1,1) primary key,
UserName nvarchar is not NULL,
Userpwd nvarchar is not NULL,
UserEmail nvarchar () null
)
Go
Then we insert 2 million data into the datasheet:
--Inserting data
SET Identity_insert tb_testtable on
DECLARE @count int
Set @count =1
Whil
This article for everyone to share the SQL Server using Row_number pagination implementation method for your reference, the specific contents are as follows
1, First is
Select Row_number () over (order by ID ASC) as ' RowNumber ', * from table1
To generate a collection with ordinal numbers
2, and then query the collection of the 1th to 5th data
SELECT * FROM
(select Row_number () "Over" (Order by ID ASC) as "RowNumber", * from table1)
This is a recently written paging stored procedure that can be applied to SQL Server 2005:
Copy Code code as follows:
If object_id (' [Proc_selectforpager] ') is not null
Drop Procedure [Proc_selectforpager]
Go
Create Proc Proc_selectforpager
(
@Sql varchar (max),
@Order varchar (4000),
@CurrentPage int,
@PageSize int,
@TotalCount int Output
)
As
/*andy 2012-2-28 * *
Declare @Exec_
SQL Server paged query stored procedure used in the project."Stored Procedures"Create PROCEDURE Prcpageresult--Get the data of a page--@currPage int = 1,--The current page number (that is, top currpage)@showColumn varchar (2000) = ' * ',--the field to be obtained (i.e. Column1,column2,......)@strCondition varchar (2000) = ",--the query condition (i.e. where condition ...) without the add where keyword@ascColumn varchar (100) = ',--Sort the field name
records can be divisible by the page size
Set @pageCount = @recordCount / @pageSize --The total number of pages is equal to the total record bar divided by the page size
Else --if the total number of records cannot be divisible by the page size
Set @pageCount = @recordCount / @pageSize + 1 --The total number of pages is equal to the total record bar divided by the page size plus 1
Set @sqlSelect =N'Select'+@columns+'From (select Row_number () over (order by'
+@
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.