I've done a bit of research on the order of index columns but am not 100% sure so please bear with me on this! I have the following table:
CREATE TABLE [Valuation]
(
[ValuationID] [int] IDENTITY(1, 1)
NOT NULL
CONSTRAINT [PK_Valuation] PRIMARY KEY ,
VersionID INT NOT NULL ,
AlphanumericIdentifier VARCHAR(255) NOT NULL,
...
other columns
...
)
I do many joins on this table to others on VersionID and AlphanumericIdentifier, so I put an index on it:
CREATE NONCLUSTERED INDEX [IX_Valuation] ON [dbo].[Valuation]
(
[VersionID] ASC,
[AlphanumericIdentifier] ASC
)
Two questions:
- These joins are usually done for a specific VersionID, so this is the most selective column and should be the first in the index - correct?
- Inserts are always done for a single version, which is 1 more than the last version. This should mitigate the performance hit on inserts as the inserted rows are a 'chunk' that can be added to the end of the index. Is this right?
I'm pretty sure that I'm right on 1, but is 2 correct?
Thanks Joe