Skip to content
Quantoros

What is the difference between CHAR and VARCHAR?

SQLLevel: FoundationFundamentals (Easy)

What is the difference between CHAR and VARCHAR?

Hints
  • Define one output row and the source-table keys.
  • Check duplicates, NULLs and the order of filtering and aggregation.

Answer

CHAR(n) is fixed-length — it always stores exactly n characters, padding with spaces if shorter. VARCHAR(n) is variable-length — it stores only as many characters as the string actually has.

CHAR can be slightly faster for fixed-length data (like country codes, status flags) because the database knows the exact size. VARCHAR is more space-efficient for variable-length strings.

In practice, on modern databases, the performance difference is negligible in most cases. Use CHAR when you know the string will always be a fixed length; use VARCHAR for everything else.

Source and licence: SQL Interview Questions — Arda Kocadoru · MIT

Related questions