Using SQL Server 2008 R2
Consider a declared table variable like:
DECLARE @t TABLE (PK int IDENTITY(1,1) PRIMARY KEY CLUSTERED, Col1 int, Col2 int)
How do I CREATE NONCLUSTERED INDEX of any name ON @t including (Con1 ASC, Col2 ASC)
The index should not be limited to unique values.
For some reason I do not manage to figure this out…
On recent versions you can create inline indexes. As below
This is tagged SQL Server 2008 however. There you can create a non clustered index as follows.
If the intention is that
Col1, Col2are unique themselves then removePKfrom the column list.Though it appears at face value as though this has added an additional column in (
PK) the index structure will be the same as creating a non unique index on justCol1, Col2on a#temptable.for a non unique non clustered index SQL Server always adds the CI key to the NCI key implicitly anyway. This just shows it explicitly.
See Kalen Delaney More About Nonclustered Index Keys