• mysql 理解 int(11)


    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等第三方软件可能没有效果。

  • 相关阅读:
    jsp内置对象
    Response响应
    中医不传之秘
    slam-四元运动学
    ubuntu 16.04 设置 win+e 快捷键打开文件夹管理器
    ubuntu16.04 更新nvidia 显卡驱动后显示 clean ... files ... blocks ... /sys/class/backlight/nvidia_0/actural_brightness
    android studio 引入模块失败解决方法
    gradle
    python logger
    ubuntu自定义终端风格
  • 原文地址:https://www.cnblogs.com/nzbbody/p/4604644.html
Copyright © 2020-2023  润新知