Yikes! There's a bunch of ambiguities with using numbers in an ENUM
field. Be careful. The one gotcha I remember is that you can access values in ENUMS
by index: if your enum is ENUM('A', 'B', 'C', '1', '2, '3')
, then these two queries are very different:
INSERT INTO TABLE (example_col) VALUES( '1' ); -- example_col == 1
INSERT INTO TABLE (example_col) VALUES( 1 ); -- example_col == A
I'm assuming the recommendation is because it limits the valid values that can get into the table. For instance, inserting 13 should get the default choice.
A better choice would by to use TINYINT
instead of INT
. an UNSIGNED TINYINT
has a range of 0 to 255 and only takes 1 byte to store. An INT
takes 4 bytes to store. If you want to constrain the values getting into the table, you can add ON INSERT
and ON UPDATE
triggers that check the values.
If you're worried about the performance difference between ENUM
and TINYINT
, you can always benchmark to see the different. This article seems somewhat relevant.