zoukankan      html  css  js  c++  java
  • INT(M)表示什么意思?

    根据官方文档描述,int(M)中的M表示数据显示的宽度,与实际存储的长度无关。

    1、也就是int(3)和int(11)能够存储的数据是一样的,都是从-21474836482147483647(或者0-4294967295)。

    2、int(M)只有联合zerofill参数才能有意义,否则int(3)和int(11)没有任何区别。

    下面用实例来证明上述两句话:

    1、创建测试表,具有int(3)、int(11)、int三个字段

    create table test_int(id int(3) unsigned not null,uid int(11) unsigned not null,uuid int unsigned not null );

    下面插入int无符号能够存储的最大值:

    insert into test_int values(4294967295,4294967295,4294967295);

    (product)root@localhost [a]> select * from test_int;
    +------------+------------+------------+
    | id         | uid        | uuid       |
    +------------+------------+------------+
    | 4294967295 | 4294967295 | 4294967295 |
    +------------+------------+------------+
    1 row in set (0.00 sec)

    【结论1】通过上述实验,对于没有加上zerofill参数的int、int(3)、int(11)无论在存储上还是在显示上都毫无区别。

    2、创建测试表,具有int(3)、int(11)、int三个字段同时加上zerofill参数

    (product)root@localhost [a]> create table test_int1(id int(3) unsigned zerofill not null,uid int(11) unsigned zerofill not null,uuid int unsigned zerofill not null );
    Query OK, 0 rows affected (0.14 sec)
    
    (product)root@localhost [a]> insert into test_int1 values(4294967295,4294967295,4294967295);
    Query OK, 1 row affected (0.03 sec)
    
    (product)root@localhost [a]> insert into test_int1 values(1,4294967295,110000);
    Query OK, 1 row affected (0.00 sec)
    
    (product)root@localhost [a]> select * from test_int1;
    +------------+-------------+------------+
    | id         | uid         | uuid       |
    +------------+-------------+------------+
    | 4294967295 | 04294967295 | 4294967295 |
    |        001 | 04294967295 | 0000110000 |
    +------------+-------------+------------+
    2 rows in set (0.00 sec)

    【结论2】通过上述实验,对于加上zerofill参数的int、int(3)、int(11),不足M宽度的,用0补充,否则不影响显示。

  • 相关阅读:
    Windows中安装Davinci
    IIS服务启动提示当文件已存在时,无法创建该文件,183
    HandyControl与LiveCharts使用出现图形位置偏移问题
    自定义面板优化统计标题卡
    WPF实现高仿统计标题卡
    C#开发微信小程序(一)
    VS2019 开发Django(一)------环境配置
    Python实现PDF转Words(文字提取)
    Python项目打包成二进制
    Python RSA加解密文本文件
  • 原文地址:https://www.cnblogs.com/mysql-dba/p/5197736.html
Copyright © 2011-2022 走看看