SQL SERVER 2012/2014 Paging, overwriting the use of row_number with Offset,fetch next

Source: Internet
Author: User

Writing:

Pretend to have a table shop, which has a list of shopname, taking 100000 to 100,050 data.

The writing of Row_number

SELECT *  from (
SELECT Over (ORDER by Shopname) as R from Shop
) TWHERE R>100000 and R<=100050

The writing of Offset,fetch

SELECT  from  Shop ORDER  by shopname OFFSET 100000 ROW FETCH NEXT  -  only

Comparison:

The difference in execution time can be clearly seen when 100,000 data are taken. Although the previous people have given a lot of arguments, I will stick to the comparison results here.

First Row_number.

And then the OFFSET FETCH .

The latter is both efficient and well-written and understandable with wood!

Private Small notes:

offset= offset, skipping

FETCH = Fetch

Alternatively, offset can be used alone, as below, skipping the top 100,000:

SELECT  from  Shop ORDER  by shopname OFFSET 100000 ROW

Off Topic:

From SQL SERVER 2000 The people are still writing top of the age, to 2005 of the Row_number, and then to 2012 of the offset FETCH, apes compatriots are really not with the tight trend is to be ruthlessly thrown down AH ~ together add a oil bar ~

SQL SERVER 2012/2014 Paging, overwriting the use of row_number with Offset,fetch next

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.