Junior — Middle
What is the purpose of a non-clustered index in a SQL database?
sobes.tech AI
Answer from AI
A non-clustered index in an SQL database is a data structure that speeds up searches on columns that are not part of the clustered index (usually not the primary key).
Purpose:
- Allows quick retrieval of rows based on the values of the indexed column.
- Does not change the physical order of data storage in the table.
- Contains pointers to the table rows, enabling efficient filtering and sorting queries.
Unlike a clustered index, which determines the physical order of rows, a non-clustered index is a separate structure, similar to a separate table with keys and links.
Example: if you have a Users table with a primary key UserId (clustered index), and you often search for users by Email, creating a non-clustered index on Email will speed up such queries.