1、这里的int(11) 与int的大小和存储字节,没有一毛钱关系,int的存储字节是4个字节,最大值为 65536*65536 = 40多亿,对于有符号的int,是20多亿。
2、那么这里的(11) 表示什么意思?
考虑下面的需求,ID字段显示宽度为2,宽度不够的补充0。
3、测试如下:
mysql> desc student;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | 0 | |
| NAME | varchar(16) | YES | MUL | NULL | |
| AGE | int(11) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

mysql> select * from student;
+-----+---------+------+
| id | NAME | AGE |
+-----+---------+------+
| 1 | Andy1 | NULL |
| 11 | Andy11 | NULL |
| 101 | Andy101 | NULL |
+-----+---------+------+

mysql> alter table student modify id int(2);
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc student;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(2) | NO | PRI | 0 | |
| NAME | varchar(16) | YES | MUL | NULL | |
| AGE | int(11) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

mysql> select * from student;
+-----+---------+------+
| id | NAME | AGE |
+-----+---------+------+
| 1 | Andy1 | NULL |
| 11 | Andy11 | NULL |
| 101 | Andy101 | NULL |
+-----+---------+------+
3 rows in set (0.00 sec)

mysql> alter table student modify id int(2) zerofill;
Query OK, 3 rows affected (0.04 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> desc student;
+-------+--------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------------------+------+-----+---------+-------+
| id | int(2) unsigned zerofill | NO | PRI | 00 | |
| NAME | varchar(16) | YES | MUL | NULL | |
| AGE | int(11) | YES | | NULL | |
+-------+--------------------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

mysql> select * from student;
+-----+---------+------+
| id | NAME | AGE |
+-----+---------+------+
| 01 | Andy1 | NULL |
| 11 | Andy11 | NULL |
| 101 | Andy101 | NULL |
+-----+---------+------+
3 rows in set (0.00 sec)

4、得出结果:
a、int(N) 必须与zerofill 结合,才能有效果。
b、只有宽度不够的,才补充0,宽度超过的,显示实际宽度。
c、使用mysql客户端有效果,使用navicat等第三方软件可能没有效果。

mysql 理解 int(11)的更多相关文章

  1. [转]MySQL中int(11)最大长度是多少?

    原文地址:https://blog.csdn.net/allenjay11/article/details/76549503 今天在添加数据的时候,发现当数据类型为 int(11) 时,我当时让用户添 ...

  2. [转载]MySQL中int(11)最大长度是多少?

    原文地址:https://blog.csdn.net/allenjay11/article/details/76549503 今天在添加数据的时候,发现当数据类型为 int(11) 时,我当时让用户添 ...

  3. MySQL中int(11)的意思

    参考文献:https://segmentfault.com/a/1190000012479448 int(11)中的11代表的是字符的显示宽度,在字段类型为int时,无论你显示宽度设置为多少,int类 ...

  4. MySQL int(11)及int(M)解析

    默认创建int类型的字段,SHOW CREATE TABLE table_name或DESC table_name常常可以看到其默认情况为int(11). 这个int(M)很多时候都会被误解为最大范围 ...

  5. mysql中整数类型后面的数字,是不是指定这个字段的长度?比如int(11),11代表11个字节吗?

    原文地址:    http://www.cnblogs.com/stringzero/p/5707467.html 原先对mysql不太理解,但也没有报错.但理解的不够深入.这次补上. 原来以为int ...

  6. mysql中整数类型后面的数字,比如int(11),11代表11个字节吗?

    原先对mysql不太理解,但也没有报错.但理解的不够深入.这次补上. 原来以为int(11)是指11个字节,int(10)就是10个字节.我错了. http://zhidao.baidu.com/li ...

  7. mysql int(3)与int(11)的区别

    总结,int(M) zerofill,加上zerofill后M才表现出有点点效果,比如 int(3) zerofill,你插入到数据库里的是10,则实际插入为010,也就是在前面补充加了一个0.如果i ...

  8. int(11)最大长度是多少,MySQL中varchar最大长度是多少(转)

    int(11)最大长度是多少,MySQL中varchar最大长度是多少? int(11)最大长度是多少? 在SQL语句中int代表你要创建字段的类型,int代表整型,11代表字段的长度. 这个11代表 ...

  9. Mysql int(11) 和 int(1)

    Mysql 可以为整数类型制定宽度,例如:int(11) ,对大多数应用这是没有意义的:它不会限制值的合法范围,它只是规定了Mysql的一些交互工具(例如mysql命令行客户端)用来显示字符个数.对于 ...

随机推荐

  1. IOS中两个view的切换

    在ios中,rootview为PassWordViewController,secondview为SecondViewController,实现在rootview中听过一个跳转按钮实现跳转到secon ...

  2. springMVC中传值的时候的乱码问题

    springMVC在传值的时候有时候回出现中文乱码的情况.有一种可能就是service的设置的问题. 打开工程中的tomcat中的servers 打开上述文件,找到下面并加上红色字体 <Conn ...

  3. Basic 分类: POJ 2015-08-03 15:49 3人阅读 评论(0) 收藏

    Basic Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 905 Accepted: 228 Description The p ...

  4. 分组排序SQL

    SELECT * FROM (SELECT columns,ROWNUM AS RN FROM (SELECT DISTINCT columns FROM table WHERE 1=1)) T WH ...

  5. inux awk命令详解

    http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858470.html 简介 awk是一个强大的文本分析工具,相对于grep的查找,sed的编 ...

  6. Poj(2771),最大独立集

    题目链接:http://poj.org/problem?id=2771 Guardian of Decency Time Limit: 3000MS   Memory Limit: 65536K To ...

  7. Bean的生命周期

    Bean的生命周期 原文:http://997004049-qq-com.iteye.com/blog/1729793 任何一个事物都有自己的生命周期,生命的开始.生命中.生命结束.大家最熟悉的应该是 ...

  8. Android JUnit Test——批量运行测试代码

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ Android测试三要素 写Android测试用例有三要素,一是我们用的“安卓模拟器device” ...

  9. mysql分库分表

    1.分库分表 很明显,一个主表(也就是很重要的表,例如用户表)无限制的增长势必严重影响性能,分库与分表是一个很不错的解决途径,也就是性能优化途径,现在的案例是我们有一个1000多万条记录的用户表mem ...

  10. Infragistics UltraGrid的使用

    OL SDK:http://help.infragistics.com/ 资料参考:http://blog.csdn.net/andy_212/article/details/4019895 http ...