Saturday, 2 November 2024

Top operator in SQL Server execution plan

The Top Operator in SQL Server execution plans is used to limit the number of rows returned by a query. It appears when a query contains a TOP clause, such as SELECT TOP N or in certain scenarios involving row limiting, like when using OFFSET-FETCH or Top Percentage. Top operator looks like as below

Let’s see the example

Simple query

select top 10* from HumanResources.Employee

This query will return top 10 records from this table.

If we are using OFFSET-FETCH in the query it will generate the top operator although we are not using here any top operator.

select * from HumanResources.Employee

order by BusinessEntityID

OFFSET 1 ROWS FETCH NEXT 10 ROWS ONLY

  
Read more about OFFSET-FETCH

Pagination in SQL Server using offset and fetch

https://bageshkumarbagi-msbi.blogspot.com/2019/07/pagination-in-sql-server-using-offset.html

Popular Posts