MySQL 中的 AUTO_INCREMENT 默认是带符号的吗?
是的,MySQL 中的 AUTO_INCREMENT 默认是带符号的(包括正数和负数)。
首先,让我们创建一张表−
mysql> create table DemoTable
-> (
-> MyNumber int AUTO_INCREMENT PRIMARY KEY
-> );
Query OK, 0 rows affected (0.45 sec)
使用 insert 命令将一些记录插入到表中。这里,我们将负数也设置为 AUTO_INCREMENT 列的值−
mysql> insert into DemoTable values() ;
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable values(-100);
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable values(-300);
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable values(0);
Query OK, 1 row affected (0.18 sec)
使用 select 语句从表中显示所有记录−
mysql> select *from DemoTable;
阅读更多:MySQL 教程
输出
+----------+
| MyNumber |
+----------+
| -300 |
| -100 |
| 1 |
| 2 |
+----------+
4 rows in set (0.00 sec)
极客教程