I have a question, related to DB theory:
Let's assume that we have table with 3 columns: [PersonID], [PersonName], [PersonAge]
.
We know that when we have a nonclustered index by one column, SQL Server orders table data in accordance with specified column and build B+ tree from it. And when we need to find the row using such an index, SQL Server scans the B++ tree by comparing one atomic data object (int
or string
, for example). That is clear, how non-clustered index works and find data when we build it by one column (suppose [PersonName]
), but what if we create non-clustered index by 2 columns: [PersonName]
and [PersonAge]
?
I understand, that during sorting criterion with main importance will be [PersonName]
and if several records have it same, than they would be sorted by [PersonAge]
. But how physically SQL Server would process the B++ tree, based on this index?
How it will use such tree when it should execute query like
SELECT *
FROM dbo.Person
WHERE [PersonName] = 'Bob' AND [PersonAge] = 45
Thanks for explaining.