Enum
Enum, short for "enumerated," is a data type that consists of predefined values. A constant or variable defined as an enum can store one of the values listed in the enum declaration.
Enums are used in both source code and database tables. For example, an enum that stores multiple colors may be declared in C# as follows:
enum Color { white, red, green, blue, black };
A column in a MySQL database table may be defined as below:
Color ENUM ('white', 'red', 'green', 'blue', 'black')
A variable or database value defined as Color can be assigned any of the five colors listed in the enum declarations above. If assigned any other value besides the one of the five colors above, it will remain undefined and may produce an error depending on the context. Also, enum variables may only contain one value. If a variable may need to store one or more predefined values, it should be defined as a SET instead.
Enums provide a highly structured way to store data since they can only store a single pre-defined value. While this helps ensure data integrity, it also limits their flexibility. Therefore, enum variables are most appropriate for storing discrete data that can only be one of a few possible values. Examples include colors, sizes, categories, months, and days of the week. Variables that contain more varied data, such as names and places, should be defined as strings.