Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use an enum or a small table in a relational database?

I have a several small entities in my database that I represent as small table with two columns: id and name. Example of such entities: countries, continent.

Should I create an enum type instead, whenever the name of those entities doesn't matter?

like image 237
ehmicky Avatar asked Jul 10 '14 15:07

ehmicky


People also ask

What is the purpose of using enum?

You should use enum types any time you need to represent a fixed set of constants. That includes natural enum types such as the planets in our solar system and data sets where you know all possible values at compile time—for example, the choices on a menu, command line flags, and so on.

Why is enum not good?

It's hard to voice what your actual needs are to a potential partner for fear that they may write you off. Transparency requires over communication. If your communication skills are already not that great, ENM is going to be more of a headache than an opportunity to be your most authentic self.

What is the correct uses of enum in MySQL?

An ENUM is a string object with a value chosen from a list of permitted values that are enumerated explicitly in the column specification at table creation time.

Which data type can be used with enum?

The enum can be of any numeric data type such as byte, sbyte, short, ushort, int, uint, long, or ulong. However, an enum cannot be a string type.


1 Answers

Hate to answer a question with a question, but it depends. How often do you expect the values to change, and how often do you release code?

Enum types will require a code change. A pure database table will be much easier to change. 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.

like image 89
Barett Avatar answered Sep 25 '22 08:09

Barett