Pagination using Query


Integration in SQL Server

A pagination process is used to separate big data into separate small pages, and this process is also known as paging. Pagination is often used for web applications and can be seen on Google. When we search for something on Google, it shows results on a separate page; this is the main idea of pagination.

Preparing Sample Data

Before we get into pagination details, we will create a sample table and fill it with specific details of the process. In the following question, we will create a SampleFruits table that stores the names of the fruits and the selling prices. In the next part of the article, we will use this table.

CREATE Sample Fruit Table (
ID INT IDENTITY KEY IDENTITY (1,1),
FruitName VARCHAR (50),
Price INT
)
GO
INSTALL SampleFruits Value ('Apple', 20)
INSTALL SampleFruits Value ('Apricot', 12)
INSTALL SampleFruits Value ('Banana', 8)
INSTALL SampleFruits Value ('Cherry', 11)
INSTALL SampleFruits Value ('Strawberry', 26)
INSTALL SampleFruits Value ('Lemon', 4)
INSTALL SampleFruits Value ('Kiwi', 14)
INSTALL SampleFruits Value ('Coconut', 34)
INSTALL SampleFruits Value ('Orange', 24)
INSTALL SampleFruits Value ('Raspberry', 13)
INSERT THE STORY BENEFITS
INSTALL SampleFruits Value ('Mandarin', 19)
INSTALL SampleFruits Value ('Pineapple', 22)
GO
SELECT * FROM EASY SampleFruits

Skin query in SQL Server

After receiving a response to "What is Pagination?" question, we will learn how to write a pagan question in SQL Server. Initially, we will do the following question and answer this question:

Announce @PageNumber AS INT
Announce @RowsOfPage AS INT
SET @ PageNumber = 2
SET @ RowsOfPage = 4
SELECT FruitName, Price FROM Sample Fruit
Order by price
OFFSET (@ PageNumber-1) * @ RowsOfPage ROWS
FETCH NEXT @RowsOfPage ROWS ONLY