You can create a non-clustered index as follows.
DECLARE @t TABLE ( PK INT IDENTITY(1, 1) PRIMARY KEY CLUSTERED, Col1 INT, Col2 INT, UNIQUE (Col1, Col2, PK))
If Col1, Col2 are Col1, Col2 be unique, then remove PK from the list of columns.
Although it appears at face value, as if it added an additional column in ( PK ), the index structure will be the same as creating a unique index only for Col1, Col2 in the #temp table.
CREATE TABLE #T ( PK INT IDENTITY(1, 1) PRIMARY KEY CLUSTERED, Col1 INT, Col2 INT) CREATE NONCLUSTERED INDEX ix ON #T(Col1, Col2)
for a non-standard non-clustered index, SQL Server always adds the CI key to the NCI key anyway. It just shows it clearly.
See Kalen Delaney for more on nonclustered index keys.
source share