为什么MySQL的布尔类型映射到tinyint而不是枚举? [英] Why does MySQL's boolean type map to a tinyint instead of an enum?

查看:159
本文介绍了为什么MySQL的布尔类型映射到tinyint而不是枚举?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在枚举上使用tinyint(1)是否存在性能或兼容性方面的原因?还有吗?

Were there performance or compatibility reasons for going with tinyint(1) over an enum? Something else?

推荐答案

您可能会想知道

It may interest you to know that MySQL indexes ENUMs with integers.

SQL标准自1999年以来就包含布尔数据类型-有效值为true,false,unknown或null. 在各种数据库系统中的实现是参差不齐的.

The SQL standard has included a boolean data type since 1999 - with valid values being true, false, unknown, or null. Implementation across various database systems is spotty.

MySQL不支持真正的布尔数据类型-BOOLEAN映射到TINYINT,仅占用1个字节. MySQL将0解释为false,其他所有数字均为true.

MySQL does not support a true boolean data type - BOOLEAN maps to TINYINT, which takes up only 1 byte. MySQL interprets 0 as false, all other numbers are true.

这篇关于为什么MySQL的布尔类型映射到tinyint而不是枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆