mysql中的unsigned - TOMMYHU - 专注互联网开发及运营技术,提供相关资料及软件下载,奇趣网络时事评论!
Jun 23

mysql中的unsigned 不指定

tommyhu , 07:53 , DBA » MYSQL , Comments(0) , Trackbacks(0) , Reads(1809) , Via Original Large | Medium | Small

unsigned 既为非负数,用此类型可以增加数据长度!

例如如果 tinyint最大是127,那 tinyint unsigned 最大 就可以到   127 * 2

unsigned 属性只针对整型,而binary属性只用于char 和varchar。

                                                                                                                                                                                                                                                                                                                                                                                
            

类型

            
            

说明

            
            

tinyint

            
            

非常小的整数

            
            

smallint

            
            

较小整数

            
            

mediumint

            
            

中等大小整数

            
            

int

            
            

标准整数

            
            

bigint

            
            

较大整数

            
            

float

            
            

单精度浮点数

            
            

double

            
            

双精度浮点数

            
            

decimal

            
            

一个串的浮点数

            



每种数值类型的名称和取值范围如表2所示。

                                                                                                                                                                                                                                                                                                                                                                                
            

类型说明

            
            

取值范围

            
            

tinyint[(m)]

            
            

有符号值:-128 到127(- 27 到27 - 1)

            

无符号值:0到255(0 到28 - 1) 1个字节

            
            

smallint[(m)]

            
            

有符号值:-32768 到32767(- 215 到215 - 1)

            

无符号值:0到65535(0 到21 6 - 1) 2个字节

            
            

mediumint[(m)]

            
            

有符号值:-8388608 到8388607(- 22 3 到22 3 - 1 )

            

无符号值:0到16777215(0 到22 4 - 1) 3个字节

            
            

int[(m)]

            
            

有符号值:-2147683648 到2147683647(- 231 到231- 1)

            

无符号值:0到4294967295(0 到232 - 1) 4个字节

            
            

bigint[(m)]

            
            

有符号值:-9223372036854775808 到9223373036854775807(- 263到263-1)

            

无符号值:0到18446744073709551615(0到264 – 1) 8个字节

            
            

float[(m, d)]

            
            

最小非零值:±1.175494351e - 38

            
            

double[(m,d)]

            
            

最小非零值:±2.2250738585072014e - 308

            
            

decimal (m, d)

            
            

可变;其值的范围依赖于m 和d

            

表2:数值列类型的取值范围

各种类型值所需的存储量如表3所示。

                                                                                                                                                                                                                                                                                                                                                                                
            

类型说明

            
            

存储需求

            
            

tinyint[(m)]

            
            

1字节

            
            

smallint[(m)]

            
            

2字节

            
            

mediumint[(m)]

            
            

3字节

            
            

int[(m)]

            
            

4字节

            
            

bigint[(m)]

            
            

8字节

            
            

float[(m, d)]

            
            

4字节

            
            

double[(m, d)]

            
            

8字节

            
            

decimal (m, d)

            
            

m字节(mysql < 3.23),m+2字节(mysql > 3.23 )

            

表3:数值列类型的存储需求

mysql提供了五种整型: tinyint、smallint、mediumint、int和bigint。int为integer的缩写。这些类型在可表示的取值范围上是不同的。 整数列可定义为unsigned从而禁用负值;这使列的取值范围为0以上。各种类型的存储量需求也是不同的。取值范围较大的类型所需的存储量较大。

mysql 提供三种浮点类型: float、double和decimal。与整型不同,浮点类型不能是unsigned的,其取值范围也与整型不同,这种不同不仅在于这些类型有最大 值,而且还有最小非零值。最小值提供了相应类型精度的一种度量,这对于记录科学数据来说是非常重要的(当然,也有负的最大和最小值)。


▲返回顶部
Last modified by tommyhu on2014/06/23 07:54

Add a comment

Nickname

emotemotemotemotemotemotemotemotemotemotemotemotemotemotemotemot