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?
- A. CHAR truncates 'cat' to a fixed-width hash
- 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
- C. Both store exactly the same bytes on disk
- 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
- A query planner chooses a full table scan over using an available index on a WHERE column. Which scenario makes this the RIGHT choice, not…
- Which statement about a query execution plan using a hash join versus a nested-loop join is correct?
- A sort-merge join requires both input relations to be sorted on the join key (or sorted as part of the plan). When is sort-merge join…
- A transaction executes BEGIN; UPDATE accounts SET balance = balance - 100 WHERE id = 1; UPDATE accounts SET balance = balance + 100 WHERE…
- A relation R(A, B, C, D, E) has candidate key AB and no other candidate keys. Which of the following dependencies, if it existed, would…
- A relation R(A, B, C, D) has candidate key AB. If C and D are both non-prime, and B → C holds (B alone, part of the key, determines C)…