INT[(M)] [UNSIGNED] [ZEROFILL]

普通大小的整数。带符号的范围是-2147483648到2147483647。无符号的范围是0到4294967295。

INT(1) 和 INT(10)本身没有区别,但是加上(M)值后,会有显示宽度的设置。

如代码所示:

mysql> create table test(id int(3));
Query OK, 0 rows affected (0.47 sec)
mysql> insert into test values(12);
Query OK, 1 row affected (0.12 sec)
mysql> insert into test values(1234);
Query OK, 1 row affected (0.10 sec)
mysql> select * from test;
+------+| id |+------+| 12 || 1234 |+------+

再试一下。这下咱们加上zerofill。

mysql> create table test1(id int(3) zerofill);
Query OK, 0 rows affected (0.32 sec)
mysql> insert into test1 value(12);
Query OK, 1 row affected (0.07 sec)
mysql> insert into test1 value(1234);
Query OK, 1 row affected (0.05 sec)
mysql> select * from test1;
+------+| id |+------+| 012 || 1234 |+------+

这下注意12前面输出多了个0,int(M) 的值多了个0,这就是显示宽度的限制。而多出来的还会显示出来。只是系统判定12显示宽度不足,会补0来补全显示宽度

但是要注意插入负数的时候:

没有设置zerofill的时候负数正常显示

mysql> insert into test value(-1234);
Query OK, 1 row affected (0.07 sec)
mysql> select * from test;
+-------+| id |+-------+| 12 || 123 || -1234 |+-------+3 rows in set (0.00 sec)

咱再来看看设置 zerofill的时候:

mysql> insert into test1 value(-1234);
Query OK, 1 row affected, 1 warning (0.11 sec)
mysql> select * from test1;
+------+| id |+------+| 012 || 1234 || 000 |+------+

输出为000,插入是-1234 。显示是000。

原来添加zerofill的时候系统会给自动添加上unsigned属性。就是非负数。而设置的显示宽度为3位。所以就会输出000。

最新文章

  1. java并发编程(4)--线程池的使用
  2. GETOBJECTOPTIONS
  3. 程序员最喜爱的12个Android应用开发框架二(转)
  4. 详解C#break ,continue, return
  5. Hibernate体系结构的简单介绍
  6. @ControllerAdvice
  7. nginx 学习八 高级数据结构之基数树ngx_radix_tree_t
  8. ubuntu下tomcat启动巨慢分析
  9. Step-by-Step XML Free Spring MVC 3 Configuration--reference
  10. allegro中数据库检查
  11. !! python 之半年总结
  12. DH11数字温湿度传感器
  13. 【Energy Big Data】能源互联网和电力大数据
  14. LeetCode 695. Max Area of Island (岛的最大区域)
  15. 关于xpath语句完全正确,但是页面报错: no such element: Unable to locate element: {"method":"xpath","selector":"xpath"}
  16. Bootstrap里的Modal框
  17. Redlock(redis分布式锁)原理分析
  18. 登录Linux服务器显示IP和自定义备注
  19. 二十七、Linux 进程与信号---进程组和组长进程
  20. 免费获取pptv会员

热门文章

  1. SSH三大框架整合配置详细步骤(2)
  2. JDK各版本内容和新特性
  3. 解决Linux环境Oracle显示乱码
  4. SWFObject 的基本使用方法
  5. Ural2004: Scientists from Spilkovo(德布鲁因序列&思维)
  6. BZOJ3224:普通平衡树(splay练习)
  7. 博弈论中的SG函数
  8. request的Content-Type小结
  9. Java-Runoob-高级教程-实例-数组:02. Java 实例 – 数组添加元素
  10. Pascal之计算小系统