Introduction

In this article, you will see the Complete Reference - Table Scan, Index Scan, and Index Seek in MSSQL.

Article Overview

Background

While working with MS SQL database and SQL, a good knowledge of how the index works and how to use them to improve the SQL query performance is very important.

Prerequisites

Difference between Scan and Seek Operation

Scan Operation Seek Operation
1. Fetches All the rows from the table Selective rows from the table
2. Touches Every single row of the table is either required or not Only the required or matching row
3. CPU Consumption More Less
4. I/O Component Usage More Less
5. Executes with SELECT statement WHERE clause


Table and Index Access

Now, let us understand each one, one by one, with practical examples.

Table Scan

For example, an Employee table with no index and the following query will use the Table scan.

SELECT * FROM Employee

Index Scan

For example, Employee table with clustered index and the following query will use the Index scan,

SELECT * FROM Employee

Index Seek

Query execution plan can show the same as it uses an index seek through created EmployeeId index,

SELECT name FROM Employee WHERE id=5

Difference between Table Scan, Index Scan and Index Seek

Table Scan Index Scan Index Seek
1. Used when? Used when we need to retrieve all the data such as 90% to 100% Used when we need to retrieve some data based on some condition such as 10% of data
2. WHERE clause The query doesn’t have a WHERE clause and the Table doesn't have clustered index then a full Table Scan is used The query doesn’t have a WHERE clause and the Table have clustered index then Index Scan is used
3. Table and Index The table is slower than the Index The index is faster than Table
4. Scan and Seek The scan is slower than Seek Seek is faster than Scan


Summary

Now, I hope you understand the key important things about Table Scan, Index Scan, and Index Seek in MSSQL.