Say I've got a table:
CREATE TABLE Users (
Id INT IDENTITY (1, 1),
FirstName VARCHAR(40),
LastName VARCHAR(40)
)
Queries are usually on FirstName or LastName, but also on FirstName and LastName.
If I create a non-clustered index on FirstName and another on LastName, then my first two queries are catered for. Apparently, SQL Server will use index intersection for the other query.
Alternatively, if I have indexees on (FirstName) and on (LastName, FirstName), can/does SQL Server use the second index for queries on just LastName as well as queries on both?
Does SQL Server store compound index parts left-to-right or right-to-left? In other words: will it build the key as LastNameFirstName or FirstNameLastName? Or is it free to choose one arbitrarily?