Should you use enums in database?

Should you use enums in database?

Enum types are more convenient for coding. For infrequent releases, or if you often have new/deleted/changed values, use a database table. For static sets of values, or if you release code all the time, use an enum.

What are the purposes of using enum and set data types?

MySQL ENUM data type contains the following advantages: Compact data storage where the column may have a limited set of specified possible values. Here, the string values automatically used as a numeric index. It allows readable queries and output because the numbers can be translated again to the corresponding string.

What is the difference between set and enum?

Difference between SET and ENUM. The difference between SET and ENUM is that SET column can contain multiple values and whereas an ENUM can hold only one of the possible values. The SET type is similar to ENUM whereas the SET type is stored as a full value rather than an index of a value as with ENUM.

Why do you need enums in a database?

By keeping the enum in your database, and adding a foreign key on the table that contains an enum value you ensure that no code ever enters incorrect values for that column. This helps your data integrity and is the most obvious reason IMO you should have tables for enums.

Do you use two tables or one enum?

Don’t use enum, do not use two tables, but just use an integer column This is like a ‘fake enum’ that requires more overhead on the code side of things, like i.e. knowing that {2 == ‘Programming’} and dealing with it appropriately.

Is there an enum datatype in SQL Server?

There is no enum datatype available in SQL Server like in MySQL. But using the CHECK constraint enum functionality can be implemented. Thanks for contributing an answer to Stack Overflow!

Is the MySQL enum part of the SQL standard?

All other options that you described are ad hoc and hacky, including MySQL’s enum, because it is not part of the SQL standard. (Other than that, what sucks with enum is MySQL’s implementation, not the idea itself.