在枚举字段上设置索引 [英] Setting the index on enum fields
I have a MySQL database which currently uses a
tinyint field to store the type of record. It uses an odd numbering, and we are in the process to change this. So currently, it reads:
record type 1 60 2 62 3 60 4 61 5 63
60 = car 61 = bike 62 = motorcycle
We need to transform this into an enum field, using the values
motorcycle. However, the table in question in being used from a very large number of pages, where SELECTs and INSERTs are being made using the original numbers. That will change gradually. So I was wondering: is there a way to change the indexes of the enum field, so that I could change the field to enum and still save a new record with type = 60, and this becomes 'car'? I know there is a way to set it to 0 and it will become car, but clearly that requires us to change all of the pages and there is no time for this...
Unfortunately this is not possible. The manual itself leaves no room for hope:
Each enumeration value has an index:
• Values from the list of permissible elements in the column specification are numbered beginning with 1.
enum提供了 any ，这给那些通过眼睛查看查询结果的程序员带来了极大的便利.您希望获得什么好处?我不是专家，但是恕我直言，无论您想要实现什么，除了使用
Seeing as there's nothing you can do about that, I have to ask: why do you need to make this an
enum? I have yet to come across a situation where an
enum provided any benefit apart convenience to programmers who look at query results by eye. What is the benefit you are looking to gain? I am no guru, but IMHO no matter what you want to achieve there is another (better) way than using an