简体   繁体   English

一位数的MySQL数据类型-tinyint(1)或smallint(1)或int(1)

[英]Mysql datatype for single digit - tinyint(1) or smallint(1) or int(1)

I need to add a column to mysql db table for storing single digits. 我需要在mysql db表中添加一列以存储一位数字。 The digits will be 0, 1, 2 , and 3 . 这些数字将是0、1、23 What should be the datatype for the column? 列的数据类型应该是什么?

tinyint(1) or smallint(1) or int(1) ? tinyint(1)smallint(1)int(1)吗?

Thats simple you can simply take tinyint for the simple reason that it takes only 1 byte(-128 to +127 / 0 to 255 (unsigned)) 太简单了,您可以简单地使用tinyint ,原因很简单,因为它仅占用1个字节(-128至+127 / 0至255(无符号))

On a side note: 附带说明:

The reason why you can avoid the other is that smallint takes 2 bytes and int takes 4 bytes, and since you have only 4 values which you want to store so no need to waste the memory. 之所以可以避免其他原因,是因为smallint占用2个字节,int占用4个字节,并且由于只存储4个值,因此无需浪费内存。

TINYINT UNSIGNED TININT签名

Read about integer types https://dev.mysql.com/doc/refman/5.1/en/integer-types.html 阅读有关整数类型的信息https://dev.mysql.com/doc/refman/5.1/en/integer-types.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM