In non-clustered index in SQL Server 2008 R2, does the index point to a single row or a group of rows?

StackOverflow https://stackoverflow.com/questions/12945160

Question

I am trying to understand how non-clustered index looks up data in a table. I think, the index when non-clustered, simply points to a data page or a group of data rows when doing lookups on the indexed column value rather than pointing to an individual row. In other words, we still need to scan a data page to get the specific data row we are looking up when using non-clustered index. Is this true?

Was it helpful?

Solution

If the non-clustered index is defined on a HEAP (table without clustered index) each index entry contains the row address: (FileId:PageNumber:SlotNumber) So in this case there is no searching necessary.

If the non-clustered index is defined on a table with a clustered index, each row in the non-clustered index contains the clustered index key. To get to the row SQL Server then has to execute a seek on the clustered index to find the containing page and then a scan of the rows within that page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top