I have a table that has the following indexes:
IXC clustered index that includes a single column : A asc.
IX1 that includes two columns : A asc, B asc.
In this case ICX seems like a duplicate index of IX1. Is it a good idea to delete ICX and make IX1 the clustered index in that case? Or is there scenarios where this would be a bad idea?
DDL example :
CREATE TABLE [dbo].[foo] (
[A] NVARCHAR (20) NOT NULL,
[B] INT NULL,
[C] NVARCHAR (20) NOT NULL,
[D] NVARCHAR (20) NOT NULL,
[E] NVARCHAR (20) NOT NULL,
);
GO
CREATE CLUSTERED INDEX [IXC]
ON [dbo].[foo]([A] ASC);
GO
CREATE NONCLUSTERED INDEX [IX1]
ON [dbo].[foo]([A] ASC, [B] ASC);
Best Answer
Take a look at this article on SQLShack which gives a great description of what to consider when selecting clustered index keys. To summarise:
So how do we apply this to your example?
You need to answer the following:
Once you've answered those questions, you should know if A or A+B is the better choice for a clustering key. If A or A+B still seem like equally valid choices for a clustering key, then considering the fact that you have an NCI with A + B would indicate you have a reasonable number of queries using both A and B as a predicate. Given that and the conditions above, A+B is likely a good candidate for a clustering key over just A if they equally satisfy the points from above.