views:

36

answers:

1

SQL Server 2005 SP3 on Windows Server 2008 R2.

I ran a server side trace, and use DTA (database engine tuning advisor) On one table DTA is suggesting me to create a nonclustered index with clustering key. I mean per DTA I need to create a composite non clustred index with explicit clustred index key as part of non clustered index.

I thought at leaf level non clustred index already includes clustering key.

MeasurementDataID is a primay key and has clustered index on it...

CREAT INDEX IX_NAME(
[MeasurementID] ASC,
[SampleName] ASC,
[MeasurementDataID] ASC )
A: 

At leaf level it does include the clustering key so the index you have will cover the query.

But if your query is

WHERE MeasurementID = 1 AND SampleName = 'foo' AND MeasurementDataID=10

Without the inclusion of MeasurementDataID it would still need to scan all records in the index matching the WHERE MeasurementID = 1 AND SampleName = 'foo' part rather than satisfy the whole thing with a seek so dependant upon how selective the first two are it might still be useful.

It's basically the same decision you need to make when considering to add a column to an index as an included column or add it to the key.

Martin Smith
I am still not clear..Is that OK to create non clustred index with clustring key explicitly? I thought SQL server will add it behind the scene..If index architecture is key value pair then does clustering key are added as key value (on a non clustred index at leaf level) or as part of the value....
cshah
It won't add it twice. If it's in the key it will recognise that and won't add it again so either add it explicitly to the key or let it add it implicitly to the leaf. Whatever makes the most sense for your queries.
Martin Smith