当前位置:Gxlcms > 数据库问题 > MySQL数据类型 int(M) 表示什么意思?

MySQL数据类型 int(M) 表示什么意思?

时间:2021-07-01 10:21:17 帮助过:2人阅读

只有跟 zerofill 结合起来,才能使我们清楚的看到不同之处。

 

mysql> drop table if exists t;
mysql> create table t(id int zerofill);
mysql> insert into t(id) values(10);

mysql> select * from t;
+------------+
| id         |
+------------+
| 0000000010 |
+------------+

mysql> alter table t change column id id int(3) zerofill;

mysql> select * from t;
+------+
| id   |
+------+
|  010 |
+------+

mysql>
mysql> alter table t change column id id int(4) zerofill;

mysql> select * from t;
+------+
| id   |
+------+
| 0010 |
+------+

mysql>
mysql> insert into t(id) values(1000000);

mysql> select * from t;
+---------+
| id      |
+---------+
|    0010 |
| 1000000 |
+---------+


从上面的测试可以看出,“(M)”指定了 int 型数值显示的宽度,如果字段数据类型是 int(4),则:当显示数值 10 时,在左边要补上 “00”;当显示数值 100 是,在左边要补上“0”;当显示数值 1000000 时,已经超过了指定宽度“(4)”,因此按原样输出。

在使用 MySQL 数据类型中的整数类型(tinyint、smallint、 mediumint、 int/integer、bigint)时,非特殊需求下,在数据类型后加个“(M)”,我想不出有何意义。

另外,在 MySQL 数据类型中,integer 和 int 同义。到底使用哪个,自己看着办吧。

 

MySQL数据类型 int(M) 表示什么意思?

标签:

人气教程排行