Today is ready to use the project to increase the paging function, the original is too limited, so the Internet to find some information recorded, the front is the use of others to summarize, the following is their own test results, haha, testing to have the basis:Three methods of paging in SQL SERVER 2008 and comparison, a friend you need can refer toCreate a ta
The paging of the SQL Server Stored Procedure has been discussed for several years. Many friends are asking me, so I would like to share my opinion on creating a table here: CREATETABLE [TestTable] ([ID] [int] IDENTITY (100) NOTNULL, [FirstName] [nvarchar] () COLLATEChinese_PRC_CI_ASNULL, [LastName]
The paging of the SQL Serv
server| Stored Procedures | Paging SQL Server Stored procedures, this issue has been discussed for several years, many friends are asking me, so here is my point of view
set up the table:
CREATE TABLE [testtable] (
[ID] [int] IDENTITY (1, 1) not NULL,
[FirstName] [nvarchar] (m) COLLATE chinese_prc_ci_as NULL,
[LastName] [nvarchar] (m) COLLATE chinese_pr
form of SQL Server using Table variables. I think many people are using this method.
DECLARE @ PAGETEMP TABLE(_ ROW_NUM int identity (1, 1 ),_ TID INT)Insert into @ PAGETEMP (_ TID) select top 30 OrderID FROM dbo. Orders order by RequiredDateSELECT [@ PAGETEMP]. _ ROW_NUM, * FROM Orders, @ pagetemp where dbo. orders. orderID = [@ PAGETEMP]. _ tid and [@ PAGETEMP]. _ ROW_NUM> 20 AND [@ PAGETEMP]. _ ROW_NUM
Create a table variable wi
syntax: LIMIT # offset #.
The code is as follows
Copy Code
Mysql> SELECT * FROM table LIMIT 5, 10; Retrieve record row 6-15, note that 10 is offsetTo retrieve all row rows from an offset to the end of a recordset, you can specify a second argument of-1:Mysql> SELECT * from table LIMIT 95,-1; Retrieves the record row 96-last.If only one argument is given, it represents the maximum number of record rows returned:Mysql> SELECT * from table LIMIT 5; Retrieves the first
Label:Recently in the analysis of the new features of offset and fetch in SQL Server 2012, it is quite good to find that the offset and fetch, whether the syntax is concise or powerful, are fairly Which offset and fetch the most important new features are used for paging, since to analyze the paging, it must be compared with the previous pagination, especially r
, @currentpage, @pagesize exec sp_cursorclose @P1 set nocount off Other scenarios: If you don't have a primary key, you can use a temporary table, or you can do it with scenario three, but the efficiency will be low. When tuning is recommended, the query efficiency increases with the primary key and index.Using SQL Query Analyzer to show comparisons: My conclusion is:Paging Scenario Two: (using ID greater than how much and select top paging) T
Question:
Data is frequently queried in applications. When the data size of the query results is large, it takes a lot of time to retrieve the results and display the interface. To avoid this problem, only part of the data should be retrieved at a time, that is, the common paging method should be used for processing. The paging problem seems very simple in Asp.net. You only need to enable
Assuming that this is page pageno, there are pagesize records per page, and now the student table is queried using MySQL, Oracle, and SQL Server paging.1. mysql Paging query:1 SELECT2 FROM4 student5 LIMIT (PageNo-1) * pagesize,pagesize;Understanding: (Limit n,m) + starts from the nth line to fetch M Records, n from 0 to calculate.2, Oracel paged query:1 S
*,rn=row_number () over(Order by CustomerId ASC) from Customers) as Twhere t.rn between (8-1) *7+1 and 8*7;select *from (select Rn=row _number () over (order by autoid ASC), * from Student) as Swhere s.rn between (3-1) *7+1 and 3*7;select Tsnam e,tsage,tclassnamefrom tblstudent as TS INNER join Tblclass as TC on TS.TSCLASSID=TC.TCLASSID;NBSP;NBSP;SE lect tsname,tsage,tclassnamefrom tblstudent as TS INNER join Tblclass as TC on Ts.tsclassi D=tc.tclassidwhere ts.tsage>20;select T1.tsname,t1.
When using SQLServer, paging processing has always been a tough issue.
When using SQL Server, paging processing has always been a tough issue.
Under normal circumstances, the SQL Server will create an appropriate index for a frequently used TableThis will greatly improve the data retrieval speed of the database itse
1. Improved version of "Russian stored procedure"
Create procedure pagination1(@ Pagesize int, -- page size, such as storing 20 records per page@ Pageindex int -- current page number)As set nocount on
Begin
Declare @ indextable table (ID int identity (), nid int) -- Define table VariablesDeclare @ pagelowerbound int -- defines the bottom code of this page.Declare @ pageupperbound int -- defines the top code of this page.
Set @ pagelowerbound = (@ pageindex-1) * @ pagesizeSet @ pageupperbound = @
1. Improved version of "Russian stored procedure"
CREATE procedure pagination1(@ Pagesize int, -- page size, such as storing 20 records per page@ Pageindex int -- current page number)As set nocount on
Begin
Declare @ indextable table (id int identity (), nid int) -- Define table VariablesDeclare @ PageLowerBound int -- defines the bottom code of this page.Declare @ PageUpperBound int -- defines the top code of this page.
Set @ PageLowerBound = (@ pageindex-1) * @ pagesizeSet @ PageUpperBound = @
mystery is here.4. SummaryThere are also some performance differences with cursors and table variables that are not considered. The paging stored procedure looks quite complex, the statement many, actually all in the judgment, in the left Assembly, the right assembly, finally assembles resembles in the title 2 commonly used pagination method one kind of statement, grasps the commonly used data pagination method, everybody can write oneself, certainly
Summary of common paging methods for SQL ServerThe following example summarizes the common paging methods for SQL Server databases, which are used only for learning referenceA, using RowNumber and between and combination paging:/********** using RowNumber and between and combination
[Transfer]The blog describes how to use datapager to implement client paging:Http://www.cnblogs.com/daizhj/archive/2009/08/07/1529331.htmlGenerally, this client paging mode is rarely used in projects unless the data volume is small (not counted by PAGE ).It is not wise to transmit a large amount of data to the client at a time. We generally pass in search condition parameters (including filter conditions and pagin
Label:Paging Query for sqlserver2005 SQLSERVER2005 has been using the top keyword to achieve paged query, but inefficient, in the sqlserver2005 and later versions of the use of row_number () parsing function to complete the paging query, the efficiency has been greatly improved, but the SQL statement is more complex, The general formula for a paged query is given below:
/* * FirstIndex: Start index
* pageSize: Number per page
* ordercolumn: Sorted
Tags:httptarrownumberota cooperation top customer display access Recently summarized the database paging SQL normally used in the project. You can post more efficient SQL statements with paging. SQL Server paging First Paging method required parameter: pagesize Ho
belong to Sarg. The reason is that the wildcard% is opened in the string so that the index is unusable. 2) or will cause a full table scan Name= ' Zhang San ' and price >5000 symbol SARG, while: Name= ' Zhang San ' or price >5000 does not conform to SARG. Using or causes a full table scan. 3) Non-operator, function-induced statements that do not satisfy the Sarg form The most typical case of a statement that does not satisfy the Sarg form is a statement that includes non-operators, such as not,
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.