You should always use enums when a variable (especially a method parameter) can only take one out of a small set of possible values. Examples would be things like type constants (contract status: "permanent", "temp", "apprentice"), or flags ("execute now", "defer execution").
An ENUM is a string object whose value is decided from a set of permitted literals(Values) that are explicitly defined at the time of column creation. Succinct data storage required to store data in limited size columns.
MySQL provides two data types ENUM and SET types. Both ENUM and SET types allow us to specify a list of possible values for a column with a default value. When defining an ENUM, we are creating a list of items from which the value must be selected or it can be NULL.
Many data types exist in MySQL to store different data into the database table. The enum data type is one of them. The full form of enum is an enumeration. When it is required to insert any particular value from the list of the predefined values into a field of a table, then an enum data type is used.
`gender` enum('female','male','rather not say','alien') NOT NULL default 'rather not say',
Is this the correct way to use enum?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With