is NULL, then 0 is returned.Then the query ID value is greater than the record of the maximum ID value for the first 40 records.This query has one condition, that is, the ID must be of type int.The third method:Select Top 10 *From(Select Row_number () over (order by ID) as rownumber,* from test) Awhere RowNumber > 40Principle: First sort all the data in the table according to a rownumber, then query rownuber more than 40 of the first 10 recordsThis approach is similar to a
There are already many paging query methods, and I am also a member here.
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 me
There are many paging methods for SQL Server 0.1 million. Is it more efficient? It will be difficult to reach the level or above. This is not an example here.
Row_number is also a major improvement over SQL server2005. For details, refer
Copy codeThe Code is as follows: SQL Server2005 General paging storage process
Create procedure [dbo]. [Common_GetPagedList](@
Table Where (ID Not In ( Select Top Page size * (Page number - 1 ) ID From Table Order By ID )) Order By ID Paging solution 2: (use the row_number () page added by SQL Server 2005) Example: 10 records are displayed on each page, and the first page is displayed:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
Paging query has a lot of ways, and here I also join as a member.
SQL Server has a SET ROWCOUNT setting that means that the processing of a command stops processing the command after responding to a specified number of rows, and this feature allows us to use it to implement a high-performance paging query in a tens of millions of row-level datasheets. First of al
(@pagesize) * FROM
(select Top (@page * @pagesize) * createtime desc) liwu_items
ORDER BY createtime ASC) b
ORDER BY createtime Desc
Results
(12 rows affected) Table ' Liwu_items '. Scan count 1, logical read 7 times, physical read 0 times, read 317 times, LOB logic read 0 times, lob physical read 0 times, lob read 0 times.
Execution plan
The execution plan is similar to the first, but two of the resources are quite a bit.
The third, one of the most rubbish, is implemented
SQL Server 2005 adds a number of new features, including Ntile and Row_numer, which make it less nerve-racking for SQL to be flexible and easy to page through (no need to envy databases like Oracle).
Here is a very simple page-splitting query:
DECLARE @rows_per_page as INTEGER
DECLARE @current_page as INTEGER
DECLARE @total_pages as INTEGER
--Set the number of rows per page
SET @rows_per_page = 20
--Set the page number to display (starting from
)*((@currentPage)-1)ORDERBYlocid
Second approach: efficiency?
1 2 3 4 5 6 7 8 9 10 11
SELECT TOP 页大小 * --如果每页显示10条数据,那么这里就是查询10条数据 FROM table1 WHERE id > --假如当前页为第三页,那么就需要查询21-30条数据,即:id>20 ( SELECT ISNULL(MAX(id),0) --查询子查询中最大的id FROM ( SELECT TOP 页大小*(当前页-1) id FROM table1 ORDER BY id --因为当前页是第三页,每页显示十条数据。那么我将: 页大小*(当前页-1),就是获取到了在"当前页""前面"的20条数据。所以上面用max(id)查询最大的id,取到这个20,那么前面的where 条件的id>20 即取到了第三页的数据,即取21-30条数据 ) as A ) ORDER BY id
Write the ab
' + @TableName + ' where ' [email protected]; --select @TotalCountSql EXEC sp_executesql @totalCountSql, N ' @TotalRecord int out ', @TotalRecord output;--returns the total number of records end If @PageSize >0 begin If @PageIndex Set @EndRecord = @StartRecord + @PageSize-1 Set @SqlString = N ' Select Row_number () over (order by ' + @OrderClause + ') as rowId, ' [email protected]+ ' from ' + @TableName + ' where ' [email protected]; Set @SqlString = ' select * FROM (' + @SqlString + ') as T
Here we can see a Data Control paging function written in SQL stored procedures, regardless of the Data Control in the development tool, you only need to call this stored procedure to implement this method. It's easy. We no longer need to write a lot of SQL statements on every page. Misrosoft SQL Server is a data management database developed by Microsoft. The most popular databases in the world are Access,
Different databases: oracle mysql SQL Server DB2 infomix sybase paging query statement, infomixsybase
Paging query statements used in different databases:
Current page: currentpagePage size: pagesize
1. Oracle Database
Select * from (select A. *, rownum rn from (QUERY_ SQL) A) where rn
Note: QUERY_ SQL is a query SQL statement.
Or
Select * from (select rownum rn
the number of the table in the message is 8000)Memory overhead evaluation can become very scary, the memory allocated for the query will reach a very large value, such as this query, the allocation of memory is 4.4G, our server is 64G memory, a few 10 of such queries will cause the server because there is no memory available to respond to subsequent requestsSo please pay special attention to this attachmen
Original address: http://www.cnblogs.com/ginponson/p/5746435.htmlAssuming 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.Paging Query for 1.MysqlSELECT * from Student -1* pagesize,pagesize;Understanding: (Limit n,m) + starts from the nth line to fetch M Records, n from 0 to calculate.Paging Query for 2.Oracel select * From ( select ROWNUM RN, *
Label:One: When paging a query, SQL Server uses the top keyword, and MySQL uses the limit e.g: Search for fifth to tenth entry-level staff SQL server2000: Select Top 6 * from EMP where empno not in (select Top 4 empno from emp Order by HireDate) order by HireDate; Mysql: SELECT * from emp order BY hire date limit 4, 6; P.s:limit a means the previous a record Limit A, a, means the record from article (a+1)
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
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.