Depends on how you query.
If you have...
WHERE PersonID = ... AND NationID = ...
...use composite index.
If you have...
WHERE PersonID = ... OR NationID = ...
...use separate indexes.
Pregunta
Note: I use Entity Framework on SQL Server 2012, if it matters.
I have a mostly-read table, it's rarely updated. Database size is not a concern, speed is.
There is a standard PK ID field. In Selects, these two are always queried on
int PersonID
int NationID
Is it faster to query if I put an index on each individually, or a single NONCLUSTERED one on both like this:
CREATE NONCLUSTERED INDEX IX_mytable_Nation_person ON dbo.mytable
(
NationId,
PersonId
) WITH( STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
Solución
Depends on how you query.
If you have...
WHERE PersonID = ... AND NationID = ...
...use composite index.
If you have...
WHERE PersonID = ... OR NationID = ...
...use separate indexes.