What is the main difference between VARCHAR and CHAR in MySQL?
VARCHAR stores variable-length strings and uses only as much space as needed plus 1 or 2 bytes for length. CHAR stores fixed-length strings and always uses the full length, padding with spaces if needed.
Click to reveal answer
beginner
When should you use TEXT instead of VARCHAR or CHAR?
Use TEXT when you need to store large amounts of text data up to 65,535 bytes (larger than the maximum effective length of VARCHAR). TEXT types are designed for longer text storage with off-row storage.
Click to reveal answer
intermediate
How does MySQL store trailing spaces in CHAR and VARCHAR columns?
CHAR pads shorter strings with spaces to fill the fixed length, and the padding spaces are removed on retrieval. VARCHAR stores the exact string without padding, preserving trailing spaces.
Click to reveal answer
intermediate
What is the maximum length of a VARCHAR column in MySQL?
The maximum length of a VARCHAR column is 65,535 bytes, but this depends on the character set and row size limits.
Click to reveal answer
advanced
Explain the storage difference between TEXT and VARCHAR in MySQL.
TEXT columns are stored outside the table row with a pointer in the row, while VARCHAR stores data directly in the row. TEXT is better for large text but can be slower to access.
Click to reveal answer
Which string type in MySQL uses fixed-length storage?
ACHAR
BTEXT
CVARCHAR
DBLOB
✗ Incorrect
CHAR uses fixed-length storage, always reserving the full length specified.
What happens if you store a shorter string in a CHAR(10) column?
AIt pads the string with spaces to length 10
BIt stores the string as TEXT
CIt truncates the string to 5 characters
DIt stores only the characters without padding
✗ Incorrect
CHAR pads shorter strings with spaces to fill the fixed length.
Which type is best for storing very long text data?
AVARCHAR
BCHAR
CTEXT
DINT
✗ Incorrect
TEXT is designed for large text data up to 65,535 bytes.
How does VARCHAR store its data in MySQL?
AFixed length with padding
BOutside the row with pointer
CAs binary data
DVariable length with length prefix
✗ Incorrect
VARCHAR stores variable-length strings with a length prefix to know the size.
What is a limitation of TEXT compared to VARCHAR?
ATEXT cannot store NULL values
BTEXT cannot be indexed fully
CTEXT has a smaller maximum size
DTEXT stores data inline always
✗ Incorrect
TEXT columns have limitations on indexing; only a prefix can be indexed.
Describe the differences between VARCHAR, CHAR, and TEXT in MySQL.
Think about storage size, padding, and typical use cases.
You got /4 concepts.
Explain how MySQL handles trailing spaces in CHAR and VARCHAR columns.
Consider how fixed vs variable length affects space storage.
You got /3 concepts.
Practice
(1/5)
1. Which MySQL string type is best for storing names that can vary in length but are usually short?
easy
A. VARCHAR
B. CHAR
C. TEXT
D. BLOB
Solution
Step 1: Understand string types for short variable-length text
VARCHAR stores variable-length strings efficiently, saving space for shorter values.
Step 2: Compare with other types
CHAR is fixed-length and wastes space if data varies; TEXT is for large text; BLOB is for binary data.
Final Answer:
VARCHAR -> Option A
Quick Check:
Variable-length short text = VARCHAR [OK]
Hint: Use VARCHAR for short, varying length text [OK]
Common Mistakes:
Choosing CHAR wastes space for variable length
Using TEXT for small strings is inefficient
Confusing BLOB with text types
2. Which of the following is the correct syntax to declare a column named description that can hold up to 255 characters using VARCHAR in MySQL?
easy
A. description VARCHAR(255)
B. description CHAR(255)
C. description TEXT(255)
D. description VARCHAR
Solution
Step 1: Recall VARCHAR syntax
VARCHAR requires a length in parentheses, e.g., VARCHAR(255).
Hint: Always specify length in parentheses for VARCHAR [OK]
Common Mistakes:
Omitting length for VARCHAR
Adding length to TEXT type
Confusing CHAR and VARCHAR syntax
3. Given the table users with a username CHAR(10) column, what will be the result of this query?
INSERT INTO users (username) VALUES ('bob'); SELECT username, LENGTH(username) FROM users WHERE username = 'bob';
medium
A. username = 'bob', LENGTH(username) = 3
B. username = 'bob ', LENGTH(username) = 3
C. username = 'bob', LENGTH(username) = 10
D. username = 'bob ', LENGTH(username) = 10
Solution
Step 1: Understand CHAR behavior on insert
CHAR(10) stores fixed length strings, padding with spaces to length 10.
Step 2: Check LENGTH function on padded string
LENGTH counts all characters including spaces, so LENGTH('bob ') = 10.
Final Answer:
username = 'bob ', LENGTH(username) = 10 -> Option D
Quick Check:
CHAR pads with spaces, LENGTH counts all chars [OK]
Hint: CHAR pads with spaces; LENGTH counts all characters [OK]
Common Mistakes:
Assuming LENGTH returns 3 for 'bob'
Ignoring space padding in CHAR
Confusing CHAR with VARCHAR behavior
4. You have a column defined as notes TEXT. You try to insert a string longer than 65,535 characters and get an error. What is the likely cause and how to fix it?
medium
A. VARCHAR max length is 65,535; use TEXT instead
B. TEXT type has a max length of 65,535 bytes; use MEDIUMTEXT for longer text
C. CHAR cannot store large text; use VARCHAR(65535)
D. TEXT type has no length limit; error is from syntax
Solution
Step 1: Recall TEXT max size limits
TEXT can store up to 65,535 bytes; longer text causes error.
Step 2: Choose correct larger text type
MEDIUMTEXT supports up to 16 million bytes, suitable for longer text.
Final Answer:
TEXT type has a max length of 65,535 bytes; use MEDIUMTEXT for longer text -> Option B
Quick Check:
TEXT max 65,535 bytes; MEDIUMTEXT for more [OK]
Hint: TEXT max 65k chars; use MEDIUMTEXT for bigger text [OK]
Common Mistakes:
Thinking TEXT has unlimited length
Using VARCHAR for very large text
Confusing CHAR with TEXT size limits
5. You want to store user comments that can be very long but also want to optimize storage for short comments. Which MySQL string type should you choose and why?
hard
A. Use VARCHAR(500) to save space for short comments and allow long ones
B. Use CHAR(500) to fix length and speed up queries
C. Use TEXT because it stores large text without fixed length
D. Use VARCHAR(65535) to cover all comment lengths
Solution
Step 1: Consider storage needs for very long text
VARCHAR max length is limited (usually 65,535 bytes total row size), so very long comments may exceed it.
Step 2: Evaluate TEXT type for large variable text
TEXT stores large text efficiently without fixed length and supports very long strings.
Final Answer:
Use TEXT because it stores large text without fixed length -> Option C
Quick Check:
Large variable text = TEXT type [OK]
Hint: Use TEXT for very long text, VARCHAR for shorter variable text [OK]
Common Mistakes:
Choosing fixed-length CHAR wastes space
Using VARCHAR too large causes errors
Assuming VARCHAR can store unlimited text
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.