✏️ Explanatory Question
Level: Basic — Tests your knowledge of MySQL's special "list-based" string types.
Both ENUM and SET restrict a column to values from a predefined list, but they differ in how many values a single cell can hold.
| Feature | ENUM | SET |
|---|---|---|
| Values per cell | Only one | Zero, one, or many |
| Max members | 65,535 | 64 |
| Internal storage | Single index | Bitmask |
| Analogy | Radio button | Checkboxes |
| Example use | status, gender, size | hobbies, permissions, tags |
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
-- ENUM: pick exactly one
gender ENUM('Male', 'Female', 'Other'),
-- SET: pick one or more
hobbies SET('Reading', 'Music', 'Sports', 'Coding')
);
-- ENUM takes a single value
INSERT INTO users (gender, hobbies)
VALUES ('Male', 'Reading,Coding'); -- SET holds multiple values
-- Query rows that include a particular SET member
SELECT * FROM users WHERE FIND_IN_SET('Coding', hobbies) > 0;