CS FundamentalsModerateAccenture · Capgemini pattern

A column is declared `VARCHAR(10)` vs. `CHAR(10)`. For a value like 'cat' (3 characters), which statement is correct about storage and comparison in most databases?

  1. A. CHAR truncates 'cat' to a fixed-width hash
  2. B. CHAR(10) pads 'cat' with trailing spaces to a fixed 10 characters (and many systems ignore trailing-space differences in comparisons), while VARCHAR(10) stores just the 3 characters (plus a small length overhead) and doesn't pad
  3. C. Both store exactly the same bytes on disk
  4. D. VARCHAR always uses MORE storage than CHAR for the same short string

Correct answer: B. CHAR(10) pads 'cat' with trailing spaces to a fixed 10 characters (and many systems ignore trailing-space differences in comparisons), while VARCHAR(10) stores just the 3 characters (plus a small length overhead) and doesn't pad

CHAR is a fixed-width type: a shorter value is padded with trailing spaces up to the declared length, and comparisons in many systems disregard trailing-space differences for CHAR data. VARCHAR is variable-length: it stores only the actual characters (with a length prefix), so short strings take noticeably less space than the equivalent CHAR column.

More DBMS and SQL questions

Exams that ask this topic