MySQL BOOL 和 BOOLEAN 列数据类型有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4753963/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:24:07  来源:igfitidea点击:

What's the difference between MySQL BOOL and BOOLEAN column data types?

mysqlsqldatatypes

提问by ikostia

I'm using MySQL version 5.1.49-1ubuntu8.1. It allows me to define columns of two different data types: BOOLand BOOLEAN. What are the differences between the two types?

我正在使用 MySQL 版本 5.1.49-1ubuntu8.1。它允许我定义两种不同数据类型的列:BOOLBOOLEAN. 这两种类型有什么区别?

回答by Adam Prax

They are both synonyms for TINYINT(1).

它们都是TINYINT(1) 的同义词。

回答by Sixthfore

As established in other comments, they're synonyms for TINYINT(1).

正如其他评论中所确定的那样,它们是 TINYINT(1) 的同义词。

*So, why do they bother differentiating between bool, boolean, tiny*int(1)?

*那么,他们为什么要费心区分 bool、boolean、tiny*int(1)?

Mostly semantics.

主要是语义。

Bool and Boolean: MySQL default converts these to the tinyint type. Per a MySQL statement made around the time of this writing, "We intend to implement full boolean type handling, in accordance with standard SQL, in a future MySQL release."

Bool 和 Boolean:MySQL 默认将这些转换为 tinyint 类型。根据撰写本文时发表的 MySQL 声明,“我们打算在未来的 MySQL 版本中根据标准 SQL 实现完整的布尔类型处理。”

0 = FALSE 1 = TRUE

0 = 假 1 = 真

TINYINT: Occupies one byte; ranges from -128 to +127; or, 0 – 256.

TINYINT:占一个字节;范围从 -128 到 +127;或者,0 – 256。



Commonly brought up in this comparison: After MySQL 5.0.3 -- Bit: Uses 8 bytes and stores only binary data.

在这个比较中经常提到: MySQL 5.0.3之后——位:使用8个字节,只存储二进制数据。

回答by SimonY

One thing I just noticed - with a column defined as BOOL in MySql, Spring Roo correctly generates Java code to unmarshall the value to a Boolean, so presumably specifying BOOL can add some value, even if it's only in the nature of a hint about the intended use of the column.

我刚刚注意到的一件事 - 在 MySql 中定义为 BOOL 的列,Spring Roo 正确生成 Java 代码以将值解组为布尔值,因此大概指定 BOOL 可以添加一些值,即使它只是关于柱的预期用途。

回答by gdp

check the MySQL docs overview of numeric types:

检查数字类型的 MySQL 文档概述:

http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html

http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html