Non Clustered Index question
Hi,
When I read about non clustered indexes I come accross this descritption:
Each index row in the nonclustered index contains the nonclustered key value and a row locator. This locator points to the data row in the clustered index or heap having the key value.
Can someone please explain what exactly is the key value? If the row locator points to the actual row of data, then what is they KEY value and what is it used for please?? (e.g., why is it needed if the row locator points to the row of data?)
Thanks.
Re: Non Clustered Index question
The Key Value is the actual data of the index. It will be equal to the data contained in the columns/fields of the table.
To find the actual location of a record within the data files, the database engine must first traverse thru the Indexes and find a match on the Key Value. Then it can use the found Row Locator to get the entire record.
Re: Non Clustered Index question
Ok thanks,
So in the following scenario...
Select * from tblCustomer where CustomerAge = 50
(CustomerAge has Non Clustered Index)
1. Traverse through nodes in B-Tree using the value 50.
2. Find the page that actually contains the value 50 in the leaf node (this is the key value).
3. When this page is found it will contain a row locator pointing to either the Clustered Index row or the heap row. (The row locator is a value (e.g. File Number / Page Number / Row Number)
Please can you let me know if any of the above is correct / incorrect please, and let me know what I have wrong.
Thanks in advance.