liveBook · Manning

Unique nonclustered index

As explained in 100 SQL Server Mistakes and How to Avoid Them

A unique nonclustered index is a nonclustered index that enforces uniqueness for its key values.

Avoid making a wide natural key or composite key the primary key merely because it must be unique. Wide keys consume disk and memory, require more index pages, and make SQL Server read more pages. Use an artificial IDENTITY primary key when appropriate, then enforce natural-key uniqueness with a unique nonclustered index. section 4.2

Natural-key uniqueness without index bloat

A table may use an automatically populated IDENTITY value as its primary key while a unique nonclustered index enforces uniqueness on the natural key. This separates the narrow physical key from the business uniqueness rule. section 4.2

Apply these checks before choosing a wide primary key:

  • Ask whether uniqueness is required only within the table or more broadly. section 4.2
  • Treat GUID primary keys cautiously because their 16-byte size and random ordering can increase page splits. section 4.2

How 100 SQL Server Mistakes and How to Avoid Them covers it

How deep it goes
Explains the design rationale and performance costs but stops short of detailed index-creation syntax.
Examples
Uses an IDENTITY primary key, a natural-key uniqueness rule, and GUID primary keys as contrasting cases.
What it assumes
Assumes basic familiarity with primary keys and indexes while contrasting clustered and nonclustered key costs.
What you can do after
Evaluate whether uniqueness belongs in a narrow primary key or a separate unique nonclustered index.
How it connects
Connects unique nonclustered indexes to primary keys, natural keys, composite keys, clustered indexes, and GUIDs.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 SQL Server Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.