liveBook · Manning

NVARCHAR

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

NVARCHAR is a SQL Server variable-length Unicode character data type that stores characters using UTF-16 encoding.

Mistake: treating NVARCHAR like a wider VARCHAR. NVARCHAR stores variable-length Unicode data with UTF-16, using two bytes per character. That supports the full UTF-16 range, but consumes more space and fits fewer characters on a data page than 8-bit character types. section 3.2

Keep these storage rules in mind:

  • Each variable-length column adds a 2-byte offset, even when its value is NULL. section 3.2
  • NVARCHAR and VARCHAR(MAX) can hold up to 2 GB; values exceeding the data page use row-overflow storage. section 3.2
  • Fixed-length UTF-16 data is limited to 4,000 characters, compared with 8,000 characters for fixed-length 8-bit data. section 3.2

Choosing a fixed-length alternative

A two-character department code can use a fixed-length Unicode column: ALTER TABLE dbo.Employees ALTER COLUMN DepartmentCode NCHAR(2);

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

How deep it goes
Explains encoding, byte cost, offset overhead, page limits, MAX storage, and row-overflow behavior.
Examples
Uses a DepartmentCode alteration to NCHAR(2) as a fixed-length Unicode example.
What you can do after
Evaluate Unicode column choices by comparing character support, storage cost, length limits, and page behavior.
How it connects
Contrasts NVARCHAR with VARCHAR, NCHAR, CHAR, UTF-8 collations, UTF-16, and row-overflow data.

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.