Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is using mysql ENUM a bad architectural solution?

For me it is like using hardcoded values instead of constant variables in application code. But there are different opinions out there. So I can't really decide for sure.

P.S. For the scope of this question let us assume that performance is not an issue.

like image 440
artemave Avatar asked May 14 '09 15:05

artemave


People also ask

Is it good to use ENUM in MySQL?

ENUM is great for data that you know will fall within a static set. If you are using Mysql 5+, storage is almost always better with an ENUM type for data in a static set, as the official MySQL reference shows. Not to mention that the data is readable, and you have an extra layer of validation.

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 difference between ENUM and set in MySQL?

For ENUM , the value is inserted as the error member ( 0 ). For SET , the value is inserted as given except that any invalid substrings are deleted. For example, 'a,x,b,y' results in a value of 'a,b' .

What is the use of ENUM data type 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.


1 Answers

It depends on what you're trying to achieve, really. If performance, as you say, is not an issue, then it's largely down to your philosophy, and the inherent changeability of the data. If you're using an ENUM to store values for days of the week, to aid human readability, and 'queryability' of the data, then it's a perfectly valid use (and far superior, in some cases, to using numbers, or other representations). If, however, you're using it to store things like the category a product is in (for which the set of available categories could easily change), then it's a very poor solution.

like image 154
James B Avatar answered Oct 17 '22 13:10

James B