Clustered and Non-Clustered Indexing
Last Updated :
08 Sep, 2025
Indexing is a performance optimization technique in SQL Server that significantly improves the speed of data retrieval operations. There are mainly two types of indexing: Clustered and Non-Clustered. Understanding the difference between them is essential for database developers and administrators to write faster and more efficient queries.
Clustered Index
A Clustered Index defines the physical order of rows in a table. When you create a clustered index on a column, SQL Server rearranges the actual data rows to match the index order. This is why a table can have only one clustered index.
A clustered index is created only when both the following conditions are satisfied:
- The data can be stored in a sequential or sorted manner.
- The column used as the key must contain unique values.
Example of Clustered Index:
Consider a table called Student where the Roll_No
column is the primary key. This automatically becomes a clustered index.
Here, SQL Server automatically creates a clustered index on the Roll_No
column. The rows are physically stored in ascending order based on the Roll_No
.
Roll_No | Name | Gender | Mob_No |
---|
4 | ankita | female | 9876543210 |
---|
3 | anita | female | 9675432890 |
---|
5 | mahima | female | 8976453201 |
---|
Explaination:
- A table can have only one clustered index.
- A clustered index can be created on multiple columns → called a composite index.
- In this case, Roll_No is the primary key, so it automatically becomes the clustered index.
- Query results are displayed in ascending order of Roll_No.
Non-Clustered Index
A Non-Clustered Index does not change the physical order of data. Instead, it creates a separate structure that stores the indexed column(s) along with pointers (row locators) to the actual rows in the table.
This separation allows you to have multiple non-clustered indexes on a single table, making them useful for columns frequently used in search conditions or joins.
Key Characteristics:
- Stores index data separately from the table.
- Multiple non-clustered indexes can exist on a table.
- Contains a copy of the indexed column(s) and a pointer to the actual data row.
Example of Non-Clustered Index:
In the Student table, we could create a non-clustered index on the Name
column. Here, roll no is a primary key, hence there is automatically a clustered index. If we want to apply a non-clustered index in the NAME column (in ascending order), then a new table will be created for that column. In this example, a non-clustered index is created on the Name
column. SQL Server will create a separate structure containing Name
and pointers to the rows where the corresponding data resides.
Query:
CREATE NONCLUSTERED INDEX NIX_FTE_Name
ON Student (Name ASC);
Output:
Roll_No | Name | Gender | Mob_No |
---|
4 | afzal | male | 9876543210 |
---|
3 | sudhir | male | 9675432890 |
---|
5 | zoyz | female | 8976453201 |
---|
Explanation:
- Creates Index: Makes a non-clustered index named NIX_FTE_Name.
- Table: The index is created on the Student table.
- Column: Applied to the Name column.
- Order: Data in the index is stored in ascending order.
- Purpose: Speeds up searches/queries on the Name column without changing the table’s actual data order.
Differences Between Clustered and Non-Clustered Index
This table organizes the primary differences between clustered and non-clustered indexes, making it easier to understand when to use each index type based on performance requirements and database structure.
Clustered Index | Non-Clustered Index |
---|
Faster for range-based queries and sorting. | Slower for range-based queries but faster for specific lookups. |
Requires less memory for operations. | Requires more memory due to additional index structure. |
The clustered index stores data in the table itself. | The non-clustered index stores data separately from the table. |
A table can have only one clustered index. | A table can have multiple non-clustered indexes. |
The clustered index can store data on the disk. | The non-clustered index stores the index structure (B-tree) on disk with pointers to the data pages. |
Stores pointers to the data blocks, not the data itself. | Stores both the indexed value and a pointer to the actual row in a separate data page. |
Leaf nodes contain the actual data itself. | Leaf nodes contain indexed columns and pointers to data. |
Defines the physical order of the rows in the table. | Defines the logical order of data in the index, not the table. |
The data is physically reordered to match the index. | The logical order does not match the physical order of rows. |
Primary keys are by default clustered indexes. | Composite keys used with unique constraints are non-clustered. |
Typically larger, especially for large primary clustered indexes. | Smaller than clustered indexes, especially when composite. |
Ideal for range queries and sorting. | Suitable for optimizing lookups and queries on non-primary columns. |
A clustered index directly impacts the table's physical storage order. | A non-clustered index does not affect the physical storage order of the table. |
Clustered Index in DBMS
Non Clustered Index in DBMS
Explore
SQL Tutorial
6 min read
Basics
Queries & Operations
SQL Joins & Functions
Data Constraints & Aggregate Functions
Advanced SQL Topics
Database Design & Security