Back-end projects developed at hand have been using the. NET MVC framework, access to the database using its own EF Codefirst model, and the ability to write stored procedures is rapidly deterioratingFree to do nothing, I wrote a page of stored procedures, similar articles on the Internet, there is only one case, based on the analysis function to generate line numbers to achieve paging queryEnvironment: SQL Server
SQL Server 202 adds new features that add OFFSET and FETCH clauses to the ORDER BY clause to achieve a paged query effect.The syntax in the ORDER BY clause is as follows: (reference: ORDER BY clause (Transact-SQL))ORDER by Order_by_expression [COLLATE collation_name] [ASC | DESC] [,... n] [In the First and NEXT are synonyms, and are provided for compatibility with ANSI.ROW and ROWS are synonyms, and are provided for compatibility with ANSI.
Tags: method create class GPO SQL Server post BSP number where--page (starting from 1) pagesize-- Method 1 (not high efficiency): SELECT TOP ten * from [XXX]. [Oooo]WHEREID not in(SELECT TOP (10* (3000-1)) ID from [XXX]. [Oooo] ORDER by Createtime DESC)ORDER by Createtime DESC; Method 2 (High efficiency): SELECT TOP 10 *From(SELECT row_number () over (ORDER by Createtime DESC) as rownumber,* from [xxx]. [Oooo]) As AWHERE RowNumber > 10* (3000-1) ORD
RPM: http://blog.csdn.net/qiaqia609/article/details/41445233 SQL Server Database paging query has been a short board for SQL Server,The first scenario, the simplest and the most common method:The code is as follows:
Select Top article WHERE ID not in (select top 45000 ID from article ORDER C11>by Year desc, ID DESC) ORDER by year desc,id desc
Killergo's Column
Recently, because of a bit of free time, I thought about how to use the paging of stored procedures on the SQL Server platform, now listed below.
In the actual test, the performance of the two is roughly equal in the case of 15,000 data, and the former is obviously better than the latter in the case of 20000-30000 data. The larger amount of data has not been tested.
Note that there are key
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'
+@
For more information about SQL Server paging query stored procedures, see.
For SQL Server paging query stored procedures, refer.
The Code is as follows:
Create procedure [dbo]. [up_Pager]
@ Table varchar (2000), -- table name
@ Col varchar (50), -- pagination by this column
@ Orderby bit, -- sort, 0-order, 1-inverted
SQL Server General paging stored procedures, with stored procedures can improve efficiency and save time.
SQL Server General paging stored procedures, with stored procedures can improve efficiency and save time.
The Code is as follows:
Create proc commonPagination
@ Columns varchar (500), -- Name of the column to be d
SQL Server database paging query has always been a short board of SQL Server, so I have nothing to worry about. I have come up with several methods, for example, table ARTICLE, field ID, YEAR... (others omitted). There are 53210 million pieces of data (the customer's actual data is not big), 30 pieces of data are queried by PAGE, 1,500th pages are queried (that i
A few SQL Server paging stored procedure writing and performance comparisonsStored procedure 5 Kinds of pagination, the following code is from the forgotten when from someone else that CTRL + C, so just as a collection, hope the author see don't Spray me.------Create a Database tutorial data_test-----Create DATABASE Data_testGoUse Data_testGoCREATE TABLE Tb_testtable--Creating tables(ID int identity (1,1) p
server| Stored Procedures | paging
Killergo's Column
Recently, because of a bit of free time, I thought about how to use the paging of stored procedures on the SQL Server platform, now listed below.
In the actual test, the performance of the two is roughly equal in the case of 15,000 data, and the former is obviously b
Environment
SQL Server 2008 R2
Problem
SQL Server Paging
Solve
Use test;
--Creates a test table create
table Test
(
ID int primary key identity,
name varchar NOT null
);
--Inserts data into
test (name) VALUES (' test1 ');
INSERT into test (name) VALUES (' test2 ');
INSERT into test (name) VALUES (' test3 ');
the page sizeSet@pageCount = @recordCount/@pageSize +1--The total number of pages is equal to the total record bar divided by the page size plus 1Set@totalCount =@recordCountSetnocount Off;end--the stored procedure is executed in the database declare @pageCountint, @totalCountintexec Proc_page_withtopmax2,95955, @pageCount output, @totalCount outputSelect 'Total Pages:'+Str (@pageCount)Select 'Total number of bars:'+str (@totalCount)C # code calls the pagin
Label: 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) = ' * ',--required field (i.e. Column1,column2,......)@strCondition varchar (2000) = ",--the query condition (i.e. where condition ...) no need to add Wherekeyword@ascColumn varchar (100) = ',--Sort the field name (i.
#tempSELECT Oo.rownumber, Oo. Orderseqno, Oo. Goodsname, Oo.companyname from(SELECT row_number () over (order by Oi.createdate DESC) as RowNumber,Oi. Orderseqno, Oi. Goodsname, Ci.companynameFrom OrderInfo oi INNER JOIN companyinfo ci on Oi.companyid=ci.companyidWHERE Oi. Createdate) as OoWHERE RowNumber BETWEEN 20--Defining cursorsDECLARE @temp_cursor Cursor--Assign a value to a cursorSET @temp_cursor =cursor for SELECT #temp. Orderseqno, #temp. Goodsname from #temp--Defines the temporary data
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.