Challenge - 5 Problems
ENUM and SET Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of ENUM column insertion
Consider a MySQL table
colors with a column color defined as ENUM('red', 'green', 'blue'). What will be the output of this query?INSERT INTO colors (color) VALUES ('yellow');
SELECT color FROM colors;MySQL
CREATE TABLE colors (color ENUM('red', 'green', 'blue')); INSERT INTO colors (color) VALUES ('yellow'); SELECT color FROM colors;
Attempts:
2 left
💡 Hint
ENUM columns accept only predefined values; invalid values are stored as empty string.
✗ Incorrect
In MySQL, inserting a value not listed in ENUM stores an empty string ('') as the value. It does not raise an error or store NULL.
❓ query_result
intermediate2:00remaining
Counting SET values stored
Given a table
user_prefs with a column prefs SET('email', 'sms', 'push'), what will be the output of this query?INSERT INTO user_prefs (prefs) VALUES ('email,sms');
SELECT FIND_IN_SET('sms', prefs) AS sms_position FROM user_prefs;MySQL
CREATE TABLE user_prefs (prefs SET('email', 'sms', 'push')); INSERT INTO user_prefs (prefs) VALUES ('email,sms'); SELECT FIND_IN_SET('sms', prefs) AS sms_position FROM user_prefs;
Attempts:
2 left
💡 Hint
FIND_IN_SET returns the position of a string in a comma-separated list.
✗ Incorrect
The SET value 'email,sms' is stored as a string 'email,sms'. FIND_IN_SET('sms', prefs) returns 2 because 'sms' is the second item in the list.
📝 Syntax
advanced2:00remaining
Valid ENUM declaration
Which of the following is a valid ENUM column declaration in MySQL?
Attempts:
2 left
💡 Hint
Default value must be one of the ENUM values or empty string.
✗ Incorrect
Option A correctly sets a default value that is one of the ENUM options. Options B and D use numeric defaults which are invalid. Option A uses a default not in the ENUM list.
❓ optimization
advanced2:00remaining
Optimizing queries with SET columns
You have a table
notifications with a SET column methods SET('email', 'sms', 'push'). Which query is the most efficient to find rows where 'sms' is one of the methods?Attempts:
2 left
💡 Hint
SET columns are stored as bitmaps internally.
✗ Incorrect
Option A uses bitwise AND to check if the bit for 'sms' (which is the second SET value) is set. This is more efficient than string functions or LIKE.
🧠 Conceptual
expert2:00remaining
Behavior of ENUM with numeric values
What happens if you define an ENUM column as
ENUM('1', '2', '3') and insert the value 2 (without quotes) into it?Attempts:
2 left
💡 Hint
ENUM values have numeric indexes starting at 1 internally.
✗ Incorrect
When inserting a number into an ENUM column, MySQL treats it as the index of the ENUM value, not as a string. So 2 stores the second ENUM value '2'.