Let's say I have a table:
CREATE TABLE Users ( Id INT IDENTITY (1, 1), FirstName VARCHAR(40), LastName VARCHAR(40) )
Queries are usually called FirstName or LastName, but also in FirstName and LastName.
If I create a non-clustered index for FirstName and another in LastName, then my first two queries are satisfied. Apparently, SQL Server will use index intersection for another query.
Alternatively, if I have indexes on (FirstName) and on (LastName, FirstName), can SQL Server use the second index for queries only for LastName, as well as for queries on both?
Does SQL Server keep index components left to right or right to left? In other words: will it build the key as LastNameFirstName or FirstNameLastName? Or can I choose arbitrarily?
performance sql-server
Roger Lipscombe
source share