mysql基础之四:int(M)中M的含义
昨天写sql文件时把以前一直不是很明白的地方弄明白了,就是在设置int型的时候,需要设置int(M),以前知道这个M最大是255,但是到底应该设置多少并没有在意。
查了下官方manual 有这样的语句:
M
indicates the maximum display width for integer types. The maximum legal display width is 255.
这个M 就是maximum display width。那什么是maximum display width?看了下面的例子很容易说明了,注意zerofill :
mysql> create table b ( b int (4));
Query OK, 0 rows affected (0.25 sec)
mysql> insert into b values ( 12345 );
Query OK, 1 row affected (0.00 sec)
mysql> select * from b;
+-------+
| b |
+-------+
| 12345 |
+-------+
1 row in set (0.00 sec)
mysql> alter table b change b b int(11);
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> select * from b;
+-------+
| b |
+-------+
| 12345 |
+-------+
1 row in set (0.00 sec)
mysql> alter table b change b b int(11) zerofill ;
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> select * from b ;
+-------------+
| b |
+-------------+
| 000000 12345 |
+-------------+
1 row in set (0.00 sec)
mysql> alter table b change b b int(4) zerofill ;
Query OK, 1 row affected (0.08 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> select * from b ;
+-------+
| b |
+-------+
| 10000 |
+-------+
1 row in set (0.00 sec)
mysql> alter table b change b b int(6) zerofill ;
Query OK, 1 row affected (0.01 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> select * from b;
+--------+
| b |
+--------+
| 0 12345 |
+--------+
1 row in set (0.00 sec)
以上的例子说明了,这个M 的表示显示宽度,他跟着zerofill 一起才有意义。就算前面设置的M的值比数值实际的长度小对数据也没有任何影响。
最新文章
- Tableview中Dynamic Prototypes动态表的使用
- SuiteScript >; Apply script to Assembly and Kit
- 推荐一个算法编程学习中文社区-51NOD【算法分级,支持多语言,可在线编译】
- Search and Replace搜寻与替换工具
- js问题解释
- lucene底层数据结构——FST,针对field使用列存储,delta encode压缩doc ids数组,LZ4压缩算法
- java基础-004
- Word Ladder II
- 轻松学Shell之认识正规表达式
- ubuntu thrift 0.9.3编译安装
- c++ 的几种强制转换的讨论
- 1081: [SCOI2005]超级格雷码
- django+Echarts实现数据可视化
- 数据库复习总结(20)-存储过程以及.net调用存储过程
- 第十二节: 总结Quartz.Net几种部署模式(IIS、Exe、服务部署【借助TopSelf、服务类】)
- 洛谷P4035 [JSOI2008]球形空间产生器(高斯消元)
- Python -- Pandas介绍及简单实用【转】
- 【题解】Luogu P4979 矿洞:坍塌
- NOIP练习赛题目2
- JQuery Mobile 简单入门引导
热门文章
- Springer Latex投稿
- LeetCode第[21][23]题(Java):Merge Sorted Lists
- aps.net session全面介绍(生命周期,超时时间)
- mysql数据库优化课程---6、mysql结构化查询语言有哪些
- CodeForces 385 D.Bear and Floodlight 状压DP
- HDU-1007-最小公共点对
- cassandra框架模型之二——存储机制 CommitLog 	MemTable SSTable
- 微信小程序入门四: 导航栏样式、tabBar导航栏
- 10.Linux网卡的配置及详解
- HashMap(HashSet)的实现