The record page code of a classic database in Asp.net

Source: Internet
Author: User

1,
Select top pagesize newstitle

Form newsinfo where newsid not in

(Select top (page-1) * pagesize newsid from newsinfo

Where auditing = 1 and newsbreed = 'enterprise news 'order by newsid DESC)

And auditing = 1 and newsbreed = 'enterprise news 'order by newsid DESC

The page indicates the current page number, and the pagesize indicates the page size. The not in clause is used here, And the Sarg is not composite, but it is better than reading all the records at a time.

2. Sarg-compliantCode

There is also a better solution for my instance: Because the newsid field is an auto-incrementing field, the not in statement is modified as follows without affecting the result. But the speed has improved a lot.

Select top pagesize newstitle

Form newsinfo where newsid <

(Select Min (newsid) from (select top (page-1) * pagesize newsid from newsinfo where auditing = 1 and newsbreed = 'enterprise News' order by newsid DESC) as TB) and auditing = 1 and newsbreed = 'enterprise news 'order by newsid DESC

[Description]
For Web applications that use the paging function in multiple placesProgram, Changing SQL statements to stored procedures will be better.

Please participate in the discussion pageAlgorithmAnd share the solution with you.

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.