3 Ways to paging SQL Server

Source: Internet
Author: User

3 Ways to paging SQL Server are as follows:

---SQL Server 2005-page statement collection

----Disadvantages:

Top: Complex SQL must be written by the user and no composite primary key is supported

Max: Users must write complex SQL and do not support non-unique column sorting

--row: sqlserver2000 not supported

--------------------------------

Id,email,qq,wechart,phone,phone1 Select Top @pagesize

The Where ID isn't in

(SELECT Top (@pagesize * (CURRENTPAGE-1)) ID from contacts order by ID ASC)

Ten ORDER by ID ASC

11

12

13-The least efficient paging statement (you only need to know the number of pages and how many per page to display)

SELECT * from Aisino_bd_telephonerecord the ORDER by ID ASC;

Select Top 5 ID for Companyid,projectid from dbo. Aisino_bd_telephonerecord

The Where ID not in (

Select Top (5* (2-1)) ID from Aisino_bd_telephonerecord ORDER by ID ASC

by ID ASC

19

20

----------------------

The second way, you need to know how many pages and the number of pages per page can be-------------------------------

22

Select Top 5 * from Aisino_bd_telephonerecord

Where Id> (

Select Max (ID)

From (select Top (5* (2-1)) ID to Aisino_bd_telephonerecord ORDER by ID ASC) TT

27)

ORDER BY ID ASC

29

30

------------------

-the third method---only need to know the number of pages and how many pages per page can be displayed----------------------------------

32

33

SELECT *

From (select Top (5* (1-1) +5) row_number () over (order by Id ASC) __rn__, * from Aisino_bd_telephonerecord) t

where __rn__>5* (1-1)

Pagination in Oracle:

Oracle has its own rownum, directly using rownum for paging:

1

SELECT *

2

From (select A.*, rownum NM

3

From (SELECT * from Aos_rms_user) a

4

where RowNum <= 5* (1-1) # +5)

5

where nm >= 5* (1-1)

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.