I have a simple table with two columns, an int identity primary key and a varchar(64). I am putting a unique constraint/index on the VarChar column to enforce uniqueness. The regular query pattern is to query the column for a value, and then use the PK value in a join to find other data in other tables.
Is there any speed benefit to making the nonclustered index unique?
Does it make sense to include the PK column in the nonclustered index, or is it already there because it is the clustered PK in the first place?
Thanks.
You don’t need to add the PK to any non-clustered indexes. As you point out, all non-clustered indexes already include the PK.
And yes, having a unique constraint will increase performance when quering that index because the query optimizer can use different mechanisms to find your data if it knows there will only ever be a single match.