Skip to content
Question 36 of 40

Q.In CHAR(10) and VARCHAR(10), what does the number 10 indicate ?

Punjab PsebCBSE Class XII Board 2019Subjective· 1mImportance★★★★★
90% · 36/40 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

The number 10 specifies the maximum storage capacity in characters: CHAR(10) always reserves exactly 10 character slots (padding with spaces if needed), while VARCHAR(10) reserves up to 10 characters, using only what the actual data requires.

The concept: fixed versus variable-length storage

When you declare a column in a database, you need to tell the system how much room to set aside for text. The number in parentheses is that instruction—it's the maximum number of characters the column can hold. But CHAR and VARCHAR interpret this limit very differently, and understanding that difference is central to choosing the right type.

CHAR is a fixed-length type. If you declare CHAR(10), the database always allocates exactly 10 character positions for every value in that column, regardless of how much text you actually store. Store "Hi" (2 characters)? The database pads it with 8 trailing spaces to fill the 10-slot box. This makes every row uniform in size, which can speed up certain operations but wastes space when your data is shorter than the limit.

VARCHAR is a variable-length type. Declare VARCHAR(10), and the database allocates only as much space as the string actually needs, up to the 10-character ceiling. Store "Hi"? It uses 2 characters (plus a small overhead byte or two to record the length). Store "Database"? It uses 8. This is space-efficient but adds a tiny bit of complexity because each value can be a different size.


Step-by-step breakdown

  1. The number is a character limit.

    In both CHAR(10) and VARCHAR(10), the 10 means the column can hold a maximum of 10 characters. Try to insert an 11-character string, and the database will either truncate it or throw an error, depending on the SQL mode.

  2. CHAR(10): fixed allocation.

    Every value stored in a CHAR(10) column occupies exactly 10 bytes (in single-byte character sets like ASCII; more in multi-byte encodings like UTF-8).

    • Insert 'SQL' → stored as 'SQL ' (7 trailing spaces).
    • Insert 'Database10' → stored as 'Database10' (exactly 10 characters, no padding needed). Trailing spaces are typically stripped on retrieval in most SQL dialects, but the storage itself is always 10 slots.
  3. VARCHAR(10): variable allocation.

    A VARCHAR(10) column uses only the space required by the actual string, plus 1 or 2 bytes to store the length.

    • Insert 'SQL' → stored as 3 characters + length prefix (total ≈ 4 bytes).
    • Insert 'Database10' → stored as 10 characters + length prefix (total ≈ 11 bytes). The 10 is still a hard cap—you cannot store more than 10 characters—but shorter strings don't waste space. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.