0
0
MySQLquery~20 mins

String types (VARCHAR, CHAR, TEXT) in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Types Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output length difference between CHAR and VARCHAR
Consider a MySQL table users with a name column defined as CHAR(10) and another column nickname defined as VARCHAR(10). If you insert the value 'John' into both columns, what will be the result of SELECT LENGTH(name), LENGTH(nickname) FROM users WHERE id = 1;?
MySQL
CREATE TABLE users (id INT PRIMARY KEY, name CHAR(10), nickname VARCHAR(10));
INSERT INTO users VALUES (1, 'John', 'John');
SELECT LENGTH(name), LENGTH(nickname) FROM users WHERE id = 1;
ALENGTH(name) = 10, LENGTH(nickname) = 4
BLENGTH(name) = 4, LENGTH(nickname) = 10
CLENGTH(name) = 4, LENGTH(nickname) = 4
DLENGTH(name) = 10, LENGTH(nickname) = 10
Attempts:
2 left
💡 Hint
Remember that CHAR pads the string with spaces to its fixed length, while VARCHAR stores only the actual string length.
🧠 Conceptual
intermediate
2:00remaining
Choosing between TEXT and VARCHAR for large strings
Which of the following is a key difference between TEXT and VARCHAR types in MySQL when storing large strings?
ATEXT columns are stored inline with the table always, VARCHAR is stored off-page.
BVARCHAR columns can store unlimited data, TEXT columns have a strict 255 character limit.
CTEXT columns can store larger amounts of data but cannot have default values, while VARCHAR has size limits but can have defaults.
DVARCHAR columns cannot be indexed, TEXT columns can be indexed fully.
Attempts:
2 left
💡 Hint
Think about size limits and default value support.
📝 Syntax
advanced
2:00remaining
Valid syntax for defining a VARCHAR column
Which of the following MySQL column definitions for a VARCHAR type is syntactically correct?
Ausername VARCHAR(256) NOT NULL DEFAULT 'guest'
Busername VARCHAR NOT NULL DEFAULT 'guest'
Cusername VARCHAR(0) NOT NULL DEFAULT 'guest'
Dusername VARCHAR(65536) NOT NULL DEFAULT 'guest'
Attempts:
2 left
💡 Hint
Check the required length specification and valid length range for VARCHAR.
optimization
advanced
2:00remaining
Optimizing storage for fixed-length strings
You have a column that stores US state abbreviations, always exactly 2 characters. Which data type choice is most storage-efficient and why?
ATEXT because it can store any length and is flexible.
BCHAR(2) because it stores fixed-length strings without overhead.
CVARCHAR(2) because it saves space by storing only actual length.
DCHAR(10) to allow future longer codes.
Attempts:
2 left
💡 Hint
Consider fixed length and storage overhead.
🔧 Debug
expert
2:00remaining
Why does this TEXT column default cause an error?
Given the table creation statement:
CREATE TABLE articles (id INT PRIMARY KEY, content TEXT NOT NULL DEFAULT '');
Why does this statement cause an error in MySQL?
ANOT NULL is not allowed on TEXT columns.
BPRIMARY KEY must be on a VARCHAR or CHAR column, not INT.
CThe empty string '' is not a valid default for any string type.
DTEXT columns cannot have default values, so DEFAULT '' is invalid.
Attempts:
2 left
💡 Hint
Check MySQL rules about default values for TEXT columns.