For tables with primary keys in SQLServer, the write efficiency is high and the SQL query on the second page is displayed.

Source: Internet
Author: User
Declare @ pageSizeint -- return the number of records for one night declare @ CurPageint -- page number (page number) declare @ Countintdeclare @ idintset @ pageSize10set @ CurPage1 -- locate if @ CurPage-1begin -- setrowcount @ pageSizeselect @ idnewsIDfromnewsT

Declare @ pageSize int -- return the number of records for one night declare @ CurPage int -- page number (page number) declare @ Count int declare @ id int set @ pageSize = 10 set @ CurPage = 1 -- locate if @ CurPage =-1 begin -- set rowcount @ pageSize select @ id = newsID on the last page from newsT

Declare @ pageSize int -- returns the number of records for one night

Declare @ CurPage int -- page number (page number)

Declare @ Count int

Declare @ id int

Set @ pageSize = 10
Set @ CurPage = 1

-- Positioning
If @ CurPage =-1
Begin
-- Last page
Set rowcount @ pageSize
Select @ id = newsID from newsTemp order by newsID
End

If @ CurPage> 0
Begin
Set @ Count = @ pageSize * (@ CurPage-1) + 1
Set rowcount @ Count
Select @ id = newsID from newsTemp order by newsID desc
End

-- Return record
Set rowcount @ pageSize
Select * from newsTemp where newsID <= @ id order by newsID desc

Set rowcount 0

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.