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 1mysql> 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的最大值是多少?的详细内容。