Using ENUM and SET Types in MySQL
📖 Scenario: You are creating a simple database for a small online store. You want to store product information including the product category and available colors. The category should be one of a few fixed options, and the colors can be multiple selections from a predefined list.
🎯 Goal: Build a MySQL table called products that uses ENUM for the product category and SET for the available colors.
📋 What You'll Learn
Create a table named
products with columns id, name, category, and colors.Use
ENUM type for the category column with values: 'Clothing', 'Electronics', 'Books'.Use
SET type for the colors column with values: 'Red', 'Green', 'Blue', 'Black', 'White'.Insert one product with category 'Electronics' and colors 'Red' and 'Black'.
💡 Why This Matters
🌍 Real World
ENUM and SET types help enforce data consistency for fields with limited options, like product categories and available colors in e-commerce databases.
💼 Career
Understanding ENUM and SET types is useful for database design roles, backend development, and data integrity management in real-world applications.
Progress0 / 4 steps