I would like to add a column to the table which contains either of two values: 1 or 0.
我想向表中添加一个列,其中包含两个值:1或0。
What would be the smallest datatype to store the data in MySQL?
在MySQL中存储数据的最小数据类型是什么?
A TINYINT(1)
can contain numbers between -127
to 127
.
TINYINT(1)可以包含-127到127之间的数字。
2 个解决方案
#1
8
You can use bit(1)
您可以使用一些(1)
http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html
http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html
BOOL is stored in MySQL as TINYINT which would take 1 full byte
BOOL以TINYINT的形式存储在MySQL中,需要一个完整的字节
http://dev.mysql.com/doc/refman/5.0/en/other-vendor-data-types.html
http://dev.mysql.com/doc/refman/5.0/en/other-vendor-data-types.html
A bit(1) would normally also take 1-byte but if there are multiple bits in a single record, then they get stored in the same byte, up to 8 per byte.
一个位(1)通常也需要1个字节,但是如果一个记录中有多个位,那么它们就会被存储在同一个字节中,最多8个字节。
#2
0
Its an ideal case for a boolean data type
它是布尔数据类型的理想情况。
#1
8
You can use bit(1)
您可以使用一些(1)
http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html
http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html
BOOL is stored in MySQL as TINYINT which would take 1 full byte
BOOL以TINYINT的形式存储在MySQL中,需要一个完整的字节
http://dev.mysql.com/doc/refman/5.0/en/other-vendor-data-types.html
http://dev.mysql.com/doc/refman/5.0/en/other-vendor-data-types.html
A bit(1) would normally also take 1-byte but if there are multiple bits in a single record, then they get stored in the same byte, up to 8 per byte.
一个位(1)通常也需要1个字节,但是如果一个记录中有多个位,那么它们就会被存储在同一个字节中,最多8个字节。
#2
0
Its an ideal case for a boolean data type
它是布尔数据类型的理想情况。