Limit sql data for each page in application

austin branham 1 Reputation point
2022-02-21T16:43:32.007+00:00

I have 5000 rows of data for a company in SQL but when I open the companies data in my app I don't want to bring all 5000 right away, I want to only bring like 100 for the first page and then when I go to the next page it brings the next 100 rows and so on. Is there a way to do that so I don't have to bring all 5000 and my app crashes?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,815 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Tom Phillips 17,731 Reputation points
    2022-02-21T17:14:07.287+00:00
    0 comments No comments

  2. CathyJi-MSFT 22,201 Reputation points Microsoft Vendor
    2022-02-22T06:24:39.833+00:00

    Hi @austin branham ,

    We recommend that you use the OFFSET and FETCH clauses instead of the TOP clause to implement a query paging solution and limit the number of rows sent to a client application. Refer to MS document Using OFFSET and FETCH to limit the rows returned.

    Suggest you reading below blog or below similar thread to get detail examples about this. If I misunderstood your question, please let me know.

    Pagination in SQL Server
    What is the best way to paginate results in SQL Server


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.