MySQL存储枚举如何? [英] How Does MySQL Store Enums?
本文介绍了MySQL存储枚举如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有这样的表:
CREATE TABLE sizes (
name ENUM('small', 'medium', 'large')
);
MySQL将在每行中存储这些字符串,或者内部将使用更小的整数知道要引用哪个枚举值?
Is MySQL going to store those strings in every row, or internally will it use something smaller like integers to know which enum value to refer to?
我想在表中使用枚举,但我担心如果将字符串存储在每一行都是浪费的话。 / p>
I want to use an enum in a table but I'm worried if it's as wasteful as storing a string in every row.
推荐答案
它将它们转换为INSERT / UPDATE上的整数,并返回到SELECT上的字符串,因此内部存储为整数,
It converts them to integers on INSERT / UPDATE and back to strings on SELECT so the internal storage is as integers but you don't get exposed to that.
您可以检索整数,如 SELECT mycolumn + 0
。
See ENUMs in MySQL 5
这篇关于MySQL存储枚举如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文