int(10)和int(11)的区别

int(M) M指示最大显示宽度。最大有效显示宽度是255。显示宽度与存储大小或类型包含的值的范围无关

MySQL也支持整数类型TINYINT、MEDIUMINT和BIGINT。下面的表显示了需要的每个整数类型的存储和范围。

类型 字节 最小值 最大值
    (带符号的/无符号的) (带符号的/无符号的)
TINYINT 1 -128 127
    0 255
SMALLINT 2 -32768 32767
    0 65535
MEDIUMINT 3 -8388608 8388607
    0 16777215
INT 4 -2147483648 2147483647
    0 4294967295
BIGINT 8 -9223372036854775808 9223372036854775807
    0 18446744073709551615

 

总结,int(M) zerofill,加上zerofill后M才表现出有点点效果,比如 int(3) zerofill,你插入到数据库里的是10,则实际插入为010,也就是在前面补充加了一个0.如果int(3)和int(10)不加zerofill,则它们没有什么区别.M不是用来限制int个数的.int(M)的最大值和最小值与undesigned有关,最下面那副图有说明.

mysql> create table t (t int(3) zerofill); Query OK, 0 rows affected (0.00 sec)
mysql> insert into t set t = 10; Query OK, 1 row affected (0.00 sec)
mysql> select * from t; +——+ | t | +——+ | 010 | +——+ 1 row in set (0.11 sec)
Zerofill with default width, the same as int(10):
mysql> create table t (t int zerofill); Query OK, 0 rows affected (0.02 sec)
mysql> insert into t set t = 10; Query OK, 1 row affected (0.02 sec)
mysql> select * from t; +————+ | t | +————+ | 0000000010 | +————+ 1 row in set (0.08 sec)
Without zerofill:
mysql> create table t (t int); Query OK, 0 rows affected (0.01 sec)
mysql> insert into t set t = 10; Query OK, 1 row affected (0.01 sec)
mysql> select * from t; +——+ | t | +——+ | 10 | +——+

1 row in set (0.00 sec) 

 

 

1 bytes = 8 bit ,一个字节最多可以代表的数据长度是2的8次方 11111111 在计算机中也就是

-128到127

 

 

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

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

 

posted @ 2016-03-26 13:56  王传明  阅读(822)  评论(0)    收藏  举报