What is the difference between CHAR, VARCHAR and NVARCHAR?

SQL Server Design Basic Fresher1–2 Yrs Conceptual 1 min read

Quick Answer

CHAR(n) is fixed length — always n bytes, padded with spaces. VARCHAR(n) is variable length — 1 byte per character plus 2 bytes overhead, non-Unicode. NVARCHAR(n) is variable length Unicode — 2 bytes per character (UTF-16), needed for any non-ASCII text. Use NVARCHAR for user-entered text, CHAR only for genuinely fixed codes.

CHAR is fixed length and space-padded — good only for codes that are always the same length. VARCHAR is variable length and one byte per character, but it's not Unicode. NVARCHAR is variable length Unicode at two bytes per character, and it's what I use for anything a user types — names, addresses — because a global app will eventually get non-ASCII input. The trap I watch for is implicit conversion: if the column is NVARCHAR and the query parameter comes in as VARCHAR, SQL Server may have to convert the whole column and you lose the index seek.

  • CHAR(2) for country codes, CHAR(1) for a status flag — fixed size, slightly faster, wastes space if the data varies.
  • VARCHAR for ASCII-only data where storage matters (URLs, base64), but risky for names/addresses in a global app.
  • NVARCHAR — the safe default for names, addresses, descriptions, anything a person types. Doubles the storage vs VARCHAR.
  • Literal prefix: N'text' is an nvarchar literal; without N it's varchar and non-ASCII characters are lost.
  • VARCHAR(MAX) / NVARCHAR(MAX) store up to 2 GB (off-row); avoid indexing or over-selecting them.
  • Implicit conversion trap: comparing an NVARCHAR column to a VARCHAR parameter can force a scan.