Furkan Gözükara
Furkan Gözükara

Reputation: 23800

Should primary key clustered index columns added to the non clustered indexes?

Ok here is a non clustered index features

enter image description here

Now as you can see Id is the Identity column which is primary key and clustered. I can either include it into the index columns and mark index as unique or not include it to the index itself and add it as included columns.

Which one should be selected and why ? thank you

Upvotes: 1

Views: 1690

Answers (1)

Mark S. Rasmussen
Mark S. Rasmussen

Reputation: 35466

The clustered key is automatically included in the nonclustered index, whether you include it explicitly or not. In other words - don't include it, unless you need to use a predicate that filters on the clustered key and then a couple of other columns (in that order) - in that case it may make sense to force it as the first column, as it'll otherwise be stored physically as the last column.

Upvotes: 5

Related Questions