liveBook · Manning

Nchar

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

NCHAR is a SQL Server fixed-length Unicode character data type that stores characters using two bytes per character.

Mistake #7: treating every string as variable-length. NCHAR is a fixed-length Unicode type; SQL Server pads shorter values with whitespace, so NCHAR(2) suits codes that always occupy two characters but can waste space for shorter or irregular data. section 3.2

Fixed length affects storage rather than merely documenting expected size. SQL Server stores rows on 8 KB pages and records fixed-length metadata, so choosing NCHAR requires considering padding, row capacity, and downstream maintenance. section 3.2

Department codes

Convert a consistently two-character department code with: ALTER TABLE dbo.Employees ALTER COLUMN DepartmentCode NCHAR(2);

Use NCHAR when the value is genuinely fixed-width; otherwise check the consequences before choosing it.

  • Choose NCHAR for codes with a stable width, not simply because a maximum length is known. section 3.2
  • Expect whitespace padding and account for its storage impact. section 3.2

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

How deep it goes
Explains whitespace padding, pages, extents, row slots, and fixed-length metadata, but stops short of broader performance analysis.
Examples
Demonstrates NCHAR with two-character DepartmentCode values and an ALTER TABLE command.
What it assumes
Assumes basic columns and strings, while teaching the distinction between fixed-length and variable-length storage from first principles.
What you can do after
Operate/configure it by selecting NCHAR for fixed-width values and altering a SQL Server column to NCHAR(2).
How it connects
Connects NCHAR with fixed-length strings, variable-length strings, SQL Server pages, row metadata, and storage selection.

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.