MySQL中SMALLINT(6) unsigned的最大值是65535。数字6不影响实际范围,它只用于在命令行上显示宽度。
有符号的最小值是
-32768
无符号的最大值是
65535
最大有符号值为
32767
让我们通过使用zerofill来理解这个问题,并使用以下查询创建一个表。
mysql> create table smallIntDemo -> ( -> FirstNumber smallint(6) zerofill -> ); Query OK, 0 rows affected (1.95 sec)
现在您可以使用插入命令在表中插入记录。每当您插入超出65535范围的值时,它将不会插入到表中,因为这是最大值。查询如下,插入小于最大范围的值。
mysql> insert into smallIntDemo values(2); Query OK, 1 row affected (0.21 sec) mysql> insert into smallIntDemo values(23); Query OK, 1 row affected (0.21 sec) mysql> insert into smallIntDemo values(234); Query OK, 1 row affected (0.17 sec) mysql> insert into smallIntDemo values(2345); Query OK, 1 row affected (0.15 sec) mysql> insert into smallIntDemo values(23456); Query OK, 1 row affected (0.48 sec)
现在,让我们看一些不会插入到表中的记录,因为它超过了最大值。
mysql> insert into smallIntDemo values(234567); ERROR 1264 (22003): Out of range value for column 'FirstNumber' at row 1 mysql> insert into smallIntDemo values(111111); ERROR 1264 (22003): Out of range value for column 'FirstNumber' at row 1
现在,您可以使用select语句显示表中的所有记录。查询如下所示 -
mysql> select *from smallIntDemo;
以下是显示使用宽度即数字的输出,即SMALLINT(6)。宽度为6。
+-------------+ | FirstNumber | +-------------+ | 000002 | | 000023 | | 000234 | | 002345 | | 023456 | +-------------+ 5 rows in set (0.00 sec)
以上就是在MySQL中,smallint(6) unsigned的最大值是多少?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号