One of the ways to improve performance is to fetch only the required data from the database. By implementing a pagination technique in the stored procedure, it would help us in getting only the required set of records. This can be made possible by making use of ROW_NUMBER() which was introduced in SQL Server 2005. Below is a sample query which would fetch 10 records for each page.

ROW_NUMBER() requires the ORDER BY clause inorder to determine the sequence in which the rows are assigned their unique ROW_NUMBER within a specified partition. Hence as you see in the above query, I’ve used the “Name” column. By passing the @index value as 0, 10, 20…you can get the pagination effect for your data.
Like this:
Like Loading...