Mysql中,int数据类型长度说明

[ 2012-04-26 10:39:43 | 作者: admin ]
字号: | |
p.s.有时候会出现 mediumint不够用的情况,用int(4)似乎就够了

int(M) 在 integer 数据类型中,M 表示最大显示宽度。
在 int(M) 中,M 的值跟 int(M) 所占多少存储空间并无任何关系。
和数字位数也无关系 int(3)、int(4)、int(8)
在磁盘上都是占用 4 btyes 的存储空间。

除了字段类型设 zerofill(补零)有点不同外,int(M) 跟 int 数据类型是相同的。
补零的情况:
mysql> desc test;
+-------+--------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------------------+------+-----+---------+----------------+
| id | int(3) unsigned zerofill | NO | PRI | NULL | auto_increment |
+-------+--------------------------+------+-----+---------+----------------+
1 row in set (0.01 sec)
mysql> select * from test ;
+------+
| id |
+------+
| 001 |
| 010 |
| 1234 |
+------+
3 rows in set (0.00 sec)
不补零:
mysql> desc test;
+-------+--------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------+------+-----+---------+----------------+
| id | int(3) | NO | PRI | NULL | auto_increment |
+-------+--------+------+-----+---------+----------------+
1 row in set (0.01 sec)
mysql> select * from test ;
+------+
| id |
+------+
| 1 |
| 10 |
| 1234 |
+------+
3 rows in set (0.00 sec)
感觉就是为了排版方便



attachments/201204/26_104435_123.jpg




参考:http://www.zhouchen33.com/index.php/archives/310
[最后修改由 admin, 于 2012-04-26 10:47:03]
评论Feed 评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=1822

这篇日志没有评论。

此日志不可发表评论。