What is the difference between CHAR and VARCHAR?
CHAR is a fixed length string type that always uses the defined length and pads shorter values with spaces. VARCHAR is a variable length type that uses only as much space as the value needs plus a small length marker. Use CHAR for values that are always the same length, like a country code, and VARCHAR for values that vary, like names.
The difference in storage
If you define CHAR(10) and store the word cat, it still occupies ten characters, padded with spaces. VARCHAR(10) storing cat uses only three characters plus a tiny length overhead, saving space when values differ in length.
country_code CHAR(2) -- always 2 letters, like IN or US
full_name VARCHAR(100) -- length varies a lot
The clean guideline is CHAR for fixed length data and VARCHAR for variable length data. Giving examples like a two letter country code for CHAR and a name for VARCHAR makes the choice obvious.
Common follow up questions
Related interview questions
Want the full SQL guide?
Read every SQL concept with notes, diagrams, and code in one place. Track your progress as you go.
Open the SQL guide All SQL questions